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,041 of 33,346   
   Andy Champ to All   
   Re: Failure to deduce template argument    
   22 Mar 12 10:20:23   
   
   From: no.way@nospam.invalid   
      
   On 22/03/2012 07:18, Daniel Krügler wrote:   
   > On 2012-03-22 01:26, Andy Champ wrote:   
   > [..]   
   >>> There are basically two ways to make this work. I'm starting with that   
   >>> one, which demonstrates the root of your problem here. It bases on an   
   >>> idiom to make the parameter Item non-deducible in   
   >>> std::function. Just define   
   >>>   
   >>> template   
   >>> struct identity { typedef T type; };   
   >>>   
   >>>   
   >>> and rewrite for_each_in to:   
   >>>   
   >>> template    
   >>> void for_each_in(   
   >>> std::vector& vec,   
   >>> std::function::type&)> functor)   
   >>> {   
   >>> std::for_each(vec.begin(), vec.end(), functor);   
   >>> }   
   >>>   
   >>   
   >> OK, I see. it's taken me a couple of minutes though. I think I'd have   
   >> trouble in the code review. it's also putting a new type "identity" into   
   >> the namespace, which I'd prefer to avoid - but that name is completely   
   >> arbitrary, so can be as mangled as I like.   
   >   
   > This is correct. In theory I could have used std::common_type instead   
   > of identity, for example. Personally I find the simpler template   
   > identity used in this idiom easier to understand.   
   >   
   Ah, we're  all working funny hours...  I hadn't thought of the   
   moderation altering times. (and thanks to the Moderators too!)   
      
   Anyway... it occurred to me in the night that   
      
   template    
   void for_each_in(   
     std::vector& vec,   
     std::function::value_type&)> functor)   
   {   
     std::for_each(vec.begin(), vec.end(), functor);   
   }   
      
   also works.  It picks up the feature you've used in 'identity' without   
   declaring a new class.   
      
   I hadn't heard of common_type. Another one to read up on in my copious   
   spare time.   
      
   Many thanks   
      
   Andy   
      
      
   --   
         [ 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