dc692743   
   From: daniel.kruegler@googlemail.com   
      
   On 2011-11-09 00:51, Daryle Walker wrote:   
   > On Nov 7, 4:12 am, Daniel Krügler   
   > wrote:   
   [..]   
   >> I don't see a problem for doing this as part of the constructor   
   >> templates constraints as well, just extend the enable_if test above.   
   >   
   > There's a special form of the sizeof operator, right? So it could be:   
   >   
   > std::enable_if<(S/R>= 1 + sizeof...(U)), bool>::type = true   
      
   Yep.   
      
   > But maybe a run-time error would be better.   
      
   I don't see why, but you need to decide.   
      
   >>> And can this system work if we let   
   >>> also let R (along with U) vary for all objects in a list? (We would   
   >>> need to sum up all the R values for a length check.)   
   >>   
   >> I'm not sure whether I really understand this particular question, but   
   >> it sounds as if this could work as well.   
   >   
   > I'm thinking of something like:   
   >   
   > template typename ... U, unsigned ... R   
   > >   
   > MyType( MyType const&o0, MyType const& ...o );   
   >   
   > Can the variadic stuff work on non-type template arguments (...R   
   > here)?   
      
   Sure. Why not?   
      
   > Even if yes, will the compiler pluck match the corresponding   
   > elements of U and R, i.e. the second argument will use the first   
   > element of U and the first element of R, the third argument will use   
   > the second element of U and the second element of R, etc.?   
      
   I have no idea, what "pluck match" means, but from the remainder of your   
   description I would say: Yes, this is how pack expansions are designed   
   to work.   
      
   > (BTW, this   
   > means that U and R must be of the same length.)   
      
   How could it be different here? The templates parameters are deduced   
   here, so the result can never end in different lengths for U... and R...   
      
   > Can the lengths be   
   > checked at compile time (R0 + Sum(elements of R)<= S), or would this   
   > have to be checked at run-time?   
      
   This can easily be done during compile-time as well, e.g.   
      
   #include    
      
   template   
   struct sum_all;   
      
   template<>   
   struct sum_all<> : std::integral_constant {};   
      
   template   
   struct sum_all : std::integral_constant::value> {};   
      
   template   
   struct MyType {   
    //...   
    template ::value <= S),   
   decltype(nullptr)>::type = nullptr   
    >   
    MyType( MyType const &o0, MyType const& ...o );   
    //...   
   };   
      
   [Just for fun I replaced the non-type template parameter, but that is no   
   required step]   
      
   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)   
|