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 33,121 of 33,346   
   James Kanze to K. Frank   
   Re: What are some simple, practical exam   
   14 Jul 13 03:26:24   
   
   From: james.kanze@googlemail.com   
      
   On Friday, July 12, 2013 8:00:03 AM UTC+1, K. Frank wrote:   
   > What are some simple examples that illustrate the benefits   
   > of template metaprogramming?   
      
   > What I have in mind would be examples that "speak to"   
   > programmers (like me) who don't have much experience   
   > with template metaprogramming.   
      
   > I'm looking for relatively simple programming challenges   
   > that most programmers would have encountered for which   
   > template metaprogramming would offer a good -- or even   
   > compelling -- solution.   
      
   How complex does it have to be to be considered template   
   metaprogramming?   
      
   In general, complex template metaprogramming will be forbidden   
   by the local coding guidelines, because it quickly leads to   
   unreadable and unmaintainable code.  But there are a lot of the   
   basics which I use almost daily: things like using a member   
      
        template    
        void   
        doFunc( T const& object, Base const* )   
        {   
            //  special handling...   
        }   
      
        template    
        void   
        doFunc( T const& object...)   
        {   
            //  more generic solutions..   
        }   
      
        template    
        void   
        func( T const& object )   
        {   
            doFunc( object, static_cast( 0 ) );   
        }   
      
   The standard uses this a lot in conjunction with traits classes   
   (another technique I use a lot) to tune template functions to   
   the type of iterator which they receive as argument.  It's   
   simple enough that just about every advanced C++ programmer   
   should be able to understand it.   
      
   --   
   James   
      
      
         [ 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