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,480 of 33,346   
   =?ISO-8859-1?Q?Daniel_Kr=FCgler?= to All   
   Re: template parameter type bound questi   
   22 Sep 11 13:47:46   
   
   21aa0f33   
   From: daniel.kruegler@googlemail.com   
      
   Am 22.09.2011 21:46, schrieb clonet:   
   > To make an example:   
   > I have an IOBase class and some specialized classes derived from   
   > IOBase (e.g.: IOBuffered, IOSingle, ...).   
   > Now I need to define a template class which should work on all types   
   > of IO.   
   >   
   > Something like:   
   >   
   > template   
      
   Don't use such a parameter name, if you are not a standard library   
   implementor! Names with an underscore followed by an uppercase latter are   
   reserved to an implementation for *any* use ([global.names] p1).   
      
   > class {   
   >  ....   
   > }   
   >   
   > Now, the problem is: is there a way to force the library user to   
   > specify a class derived from IOBase as _TIO?   
   >   
   > In java generics one can use constructs like ...... ,   
   > in C++?   
      
   The most relevant question would be: What should happen, if the   
   type does not satisfy the constraints? If a reasonable error message is   
   sufficient, you could write:   
      
   #include    
      
   template    
   class X {   
   static_assert(std::is_base_of::value, "Template argument must be   
   equal to IOBase or derived from IOBase");   
   ....   
   };   
      
   for a strict derivation requirement you can express this as   
      
   std::is_base_of::value && !std::is_same::value   
      
   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