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,707 of 33,346   
   =?ISO-8859-1?Q?Daniel_Kr=FCgler?= to All   
   Re: outer_class type trait?   
   30 Nov 11 19:33:44   
   
   2f0348ef   
   From: daniel.kruegler@googlemail.com   
      
   Am 30.11.2011 21:48, schrieb kispaljr:   
   > Is it possible to write a type trait template that can be used to get   
   > the outer class of a nested class/enum?   
      
   No problem, just declare:   
      
   template   
   struct outer_class_of {};   
      
   template   
   struct is_nested_in : std::false_type {};   
      
   and require that people specialize these traits for their   
   outer-inner-type combinations.   
      
   I guess that is not what you meant, though. In the following I assume   
   you mean a fully automatic solution, so lets proceed:   
      
   > I am thinking of something like this:   
   >   
   > struct outer { struct inner {}; };   
   >   
   > outer_class_of::type =>  would be a typedef for 'outer'   
   > outer_class_of::type =>  would cause a non-existing member   
   > compiler error (like enable_if)   
      
   I don't think that this can be automated. Note that this would clearly   
   conflict with name-lookup rules. If you as for   
      
   outer_class_of   
      
   inner will be looked in the current scope. So you would need to ask for   
      
   outer_class_of   
      
   (assuming that outer is in the current scope). At this point we see that   
   this trait is not very helpful in general. It would only help, if   
   someone had created a typedef, like   
      
   typedef outer::inner io;   
      
   Now you like to know whether io has some parent type. This would   
   probably require compiler intrinsics.   
      
   > or maybe something like:   
   > is_nested_in::value =>  true   
   > is_nested_in::value =>  false   
      
   We have the same name-lookup issue as above.   
      
   > I assume even if it is possible (I think it is maybe not) it would   
   > require support from the compiler and the solution would not be   
   > portable.   
   > At the moment it would be fine with me, I just want to find a solution   
   > that works with gcc 4.6.   
      
   If I correctly understand you, this does not work at all.   
      
   > If it is not possible with the current standard, do you think it would   
   > make sense to include it in the following versions?   
      
   No, if I understood you correctly.   
      
   HTH & Greetings from Bremen,   
      
   Daniel Krügler   
      
      
   --   
         [ 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