home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.lang.c++.moderated      Moderated discussion of C++ superhackery      33,346 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 31,448 of 33,346   
   Johannes Schaub to Alok   
   Re: C++ Templates: The complete Guide in   
   04 Sep 11 15:36:13   
   
   1ebc204a   
   From: schaub.johannes@googlemail.com   
      
   Alok wrote:   
      
   > I was just wondering, How far does the book:   
   >   
   > C++ Templates: The complete Guide   
   > by David Vandevoorde & Nicolai Josutils,   
   >   
   > hold good in context of the the new C++11 standard? What are the   
   > relevant areas which will need an update, or don't hold good anymore   
   > within the modifications that will come through in C++11?   
   >   
   >   
      
   One area that definitely needs an update are the relaxed typename rules. In   
   C++11 you often don't need it anymore:   
      
        template   
        struct A {   
          typedef int type;   
          A::type x;   
        };   
      
   The declaration "A::type x" is well-formed in C++11 while it's   
   ill-formed in   
   C++03. "type" is a member of the current instantiation. However, still   
   specifying "typename" there won't hurt - it's optional.   
      
   In other areas, C++11 is incompatible to C++03. The book makes use of   
   policies by inheriting from a virtual base class. C++11 makes some of those   
   uses ill-formed, but I believe I checked the book and didn't find it   
   affected by these changes (i could have overlooked something...); still   
   it's   
   good to know about it:   
      
        struct BasePolicy {   
          typedef int slaptype;   
          typedef float whiptype;   
        };   
      
        template   
        struct Configurable : virtual BasePolicy, Pol1 {   
          typename Configurable::whiptype whipkind;   
        };   
      
   Say that the user modifies "whiptype" as follows   
      
        struct DoubleWhipper : virtual BasePolicy {   
          typedef double whiptype;   
        };   
      
        // ill-formed in C++11, well-formed in C++03   
        Configurable c;   
      
   In C++03 "Configurable::whiptype" is a dependent type and looked up at   
   instantiation time and will find DoubleWhipper::whiptype unambiguously   
   using   
   the dominance rule. But in C++11, "Configurable::whiptype" is a non-   
   dependent type, but will be looked up twice to check consistency: In the   
   definition of Configurable, and when it is instantiated. The program   
   will be   
   ill-formed if both lookups are different, which is the case in the above   
   (first lookup will find BasePolicy::whiptype, second lookup by dominance   
   will find DoubleWhipper::whiptype).   
      
      
      
   --   
         [ See http://www.gotw.ca/resources/clcm.htm for info about ]   
         [ comp.lang.c++.moderated.    First time posters: Do this! ]   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca