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,639 of 33,346   
   SG to MJanes   
   Re: template argument deduction for over   
   07 Nov 12 09:40:06   
   
   d4169a30   
   From: s.gesemann@googlemail.com   
      
   On Nov 6, 6:10 pm, MJanes  wrote:   
   > { Your article lacks the context of what it's referring to.   
   >   Please include some quoting to establish the context. -mod }   
   >   
   > I forgot one thing: of course, regarding your original std::all_of   
   > use case, a simpler solution could be just something like:   
      
     struct A {};   
     struct B {};   
      
     bool p(A const&);   
     bool p(B const&);   
      
     template   
     void callP(Iter iter, Pred pred);   
      
   > void f()   
   > {   
   >    std::vector as;   
   >    callP( as.begin(), static_cast( p ) );   
   > }   
      
   Or better yet:   
      
        callP( as.begin(), [](A const& x){return p(x);} );   
      
   The difference is that in this case the callP specialization directly   
   calls your lambda (which can be inlined) and your lambda directly   
   calls p (which could also be inlined if the definition of p is   
   available in the same translation unit or you can use LTO) -- as   
   opposed to an indirect function call via function pointer.   
      
   Cheers!   
      
      
   --   
         [ 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