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,033 of 33,346   
   Andy Champ to All   
   Failure to deduce template argument to s   
   20 Mar 12 22:36:21   
   
   From: no.way@nospam.invalid   
      
   That title should be enough of a mouthful...   
      
   In the absence of range-based for I thought I'd try to knock up a helper   
   to get me in the right direction.  But I couldn't get it to build.   
      
   I could change "for-each_in" to have two template parameters, but I   
   can't see why this wouldn't work.  There's only one possible value for   
   Item, yet it can't tie it all up.  Is this a feature of MS VC++ (I'm   
   using 2010, and I've tried the 2011 beta) or is it a language subtlety?   
      
   (The error under VC++ states that it can't deduce the template parameter   
   for std::function from the lambda)   
      
   Andy   
      
   #include    
   #include    
   #include    
      
   class fred   
   {   
   public:   
     fred(){}   
     void method(){};   
   };   
      
   template    
   void for_each_in(   
     std::vector& vec,   
     std::function functor)   
   {   
     std::for_each(vec.begin(), vec.end(), functor);   
   }   
      
   int main()   
   {   
     std::vector data;   
     for_each_in(data, [](fred& datum)   
     {   
       datum.method();   
     });   
   }   
      
      
   --   
         [ 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