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 31,840 of 33,346   
   =?ISO-8859-1?Q?Daniel_Kr=FCgler?= to kelvSYC   
   Re: Template argument deduction   
   24 Jan 12 00:36:13   
   
   26f0200d   
   From: daniel.kruegler@googlemail.com   
      
   On 2012-01-24 02:41, kelvSYC wrote:   
   > I'm having a problem where it would seem like template arguments could   
   > be deduced, but in reality the compiler barfs because it can't.   
   > Suppose I have this generic functor:   
   >   
   > struct HeapConvertInserter {   
   >     template   
   >     shared_ptr  operator()(const Key&  key) { return   
   > shared_ptr(new Value(key)); }   
   > };   
      
   OK, so we have here again the same situation as in your thread "The   
   first template argument" where I explained that this operator() overload   
   is not very useful and suggested a different design.   
      
   > Now, consider a class which wraps a std::map>   
   > and some kind of delegate class like HeapConvertInserter.  One method   
   > which uses the two goes as follows:   
   >   
   > // table is the std::map>  instance, delegate is   
   > the HeapConvertInserter instance   
   > if (table.count(key) == 0) {   
   >     table.insert(std::map>::value_type(key,   
   > delegate(key)));   
   > }   
   >   
   > When I try to compile, apparently it can't deduce the Value template   
   > argument of the HeapConvertInserter's operator(),   
      
   Correct, for reasons as explained elsewhere.   
      
   > even though it would appear that Value should appear as, well, Value   
   > as defined in the std::map instance.   
      
   I don't understand how you come to the conclusion that the compiler   
   understands your intentions?   
      
   > Why is this happening?   
      
   The reasons are the same as before.   
      
   > Is there a way to make   
   > this work without moving the Value off of the operator() template and   
   > into the class template?   
      
   As suggested in the other thread, you could replace the operator()   
   overload by a member function template (e.g. "call") and invoke it by   
   providing the return type argument explicitly.   
      
   HTH & Greetings from Bremen,   
      
   Daniel Krügler   
      
      
   --   
         [ 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