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,857 of 33,346    |
|    Marc to Daryle Walker    |
|    Re: Initializing an array non-static mem    |
|    26 Jan 12 23:45:39    |
   
   feadd3c8   
   From: marc.glisse@gmail.com   
      
   Daryle Walker wrote:   
      
   > template < typename T, unsigned N >   
   > class my_math_vector   
   > {   
   > public:   
   > constexpr my_math_vector() : c{} {}   
   > constexpr my_math_vector( T const &first ) : c{first} {}   
   > constexpr my_math_vector( T const &val, unsigned index );   
   > // make this->c[index] == val, all other this->c[x] == T()   
   > //...   
   > private:   
   > T c[ N ];   
   > };   
   >   
   > It's easy to fill in an array from the front during a constexpr constructor.   
   > Is it possible to initialize a single array element that is NOT the first   
   > one? You can't know statically how many zero (or "T()") to put before your   
   > desired value, which prevents a direct solution. But maybe there's some   
   > sort of recursive template metaprogramming that can do it?...   
      
   (completely untested)   
   You can delegate to:   
   template
|
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca