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,676 of 33,346   
   Martin Senst to Daryle Walker   
   Re: Can C++ variadic arguments be enforc   
   15 Nov 11 11:45:12   
   
   25e79fea   
   From: msenst@ice.rwth-aachen.de   
      
   Daryle Walker wrote:   
      
      
   > The constructor and dependency-filler methods are templated on the   
   > types of the dependencies, but those dependencies always have to be   
   > MyType, which I try to enforce with FillDependencies.  I've never seen   
   > C++ variadic functions like:   
   >   
   >     MyFunction( int arg1, int... args );   
   >   
   > with no templating.  Is it just too rare to be in an example, or is it   
   > banned?  If the latter, I just have to do what I have seen in   
   > examples:   
   >   
   >     template    
   >     MyFunction( int arg1, Args... args );   
   >   
   > and use std::enable_if, or similar, to limit Args to int (or something   
   > convertible to int).   
      
      
      
   The following should work:   
      
   void f(int i)   
   {   
     // do something   
   }   
      
   template    
   void f(int i, int j, Tail... tail)   
   {   
     // do something with i.   
     f(j, tail...);   
   }   
      
      
   The second version ensures that the first two parameters have type int, and   
   because of the recursive call, all parameters need to have type int.   
      
   Martin   
      
      
   --   
         [ 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