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 32,385 of 33,346   
   Dave Abrahams to All   
   Re: Assembling a compile-time list of ty   
   07 Jun 12 14:10:17   
   
   From: dave@boostpro.com   
      
   on Wed Jun 06 2012, kispaljr  wrote:   
      
   > I have a bad feeling about this, since such a construction would mean   
   > that e.g. LastElementOf::type would compile to different types   
   > at different points of the source file (before and after adding a new   
   > element), and it seems bogus to me. (It smells like a 'compile time   
   > variable'.) Nevertheless that is exactly what I want now.   
   >   
   > Do you think it is possible somehow? C++11 is allowed.   
   > (I've already asked this on Stack Overflow, but didn't get an answer.)   
      
   You can't do that.  Compile-time C++ is a pure functional language.   
   However, you can still compute anything you want.  You just have to do   
   it by creating new values rather than modifying a value.  That is, you   
   can't "add an element to a list."  Instead, you can "create a new list   
   that contains everything in the old list plus the new element."   
      
        template  struct cons;   
        struct nil;   
      
        typedef cons > some_list;   
      
        // doesn't change some_list   
        typedef cons a_longer_list;   
      
   that's why, in MPL, push_back "returns" a new sequence.   
      
        typedef   
          mpl::push_back::type   
        a_longer_sequence;   
      
   HTH,   
      
   --   
   Dave Abrahams   
   BoostPro Computing   
   http://www.boostpro.com   
      
      
         [ 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