63e405b1   
   From: dave@boostpro.com   
      
   on Wed Jan 04 2012, Gene Bushuyev wrote:   
      
   > It's a very fundamental rule that members of a template are not   
   > implicitly instantiated until they are used. That reduces the   
   > compilation time, size of libraries, cuts on dependencies, and makes   
   > sfinae possible.   
      
   I don't think this has anything to do with SFINAE, which applies to   
   ordinary function templates that aren't class members. You may be   
   thinking of the a similar advantage: it's easy to make class templates   
   with optional features that are supported depending on details of the   
   template parameters. For example, if T is LessThanComparable, you can   
   call std::list::sort without arguments.   
      
    l.sort()   
      
   This overload of std::list::sort() contains code   
   that evaluates   
      
    x < y   
      
   where x and y are of type T.   
      
   If the overload of list::sort that takes no arguments was eagerly   
   instantiated, list would not be usable at all with a T that isn't   
   LessThanComparable:   
      
    struct X {};   
      
    std::list l; // <== compilation would fail in sort()   
      
   Since list::sort is instantiated only when used, we can make a   
   list, and we're fine as long as we don't try to sort it.   
      
   --   
   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)   
|