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,637 of 33,346   
   Jens Auer to All   
   template argument deduction for overload   
   06 Nov 12 07:48:12   
   
   From: jens.muaddib@googlemail.com   
      
   Hi,   
      
   I have problem with template argument deduction when using an   
   overloaded function as a predicate for std::all_of. What I want to do   
   is the following:   
   #include    
   #include    
      
   struct A {};   
   struct B {};   
      
   bool p(A const&);   
   bool p(B const&);   
      
      
   void f()   
   {   
      std::vector as;   
      
      bool b = std::all_of( as.begin(), as.end(), p);   
   }   
      
   , but the compiler complains that it cannot deduce the type   
   of the predicate parameter for std::all_of.   
   error C2914: 'std::all_of' : cannot deduce template argument as function   
   argument is ambiguous   
   error C2784: 'bool std::all_of(_InIt,_InIt,_Pr)' : could not deduce template   
   argument for '_InIt' from 'std::_Vector_iterator<_Myvec>'   
              with   
         [   
                  _Myvec=std::_Vector_val>   
              ]   
     see declaration of 'std::all_of'   
      
   I can strip this down to   
   template void callP(T i, P f)   
   {   
   	f(*i);   
   }   
      
   void f()   
   {   
      std::vector as;   
      callP( as.begin(),  p);   
   }   
   which does not compile with the same error, but I do not see the   
   reasoning behind this. My thinking is: The compiler has two candidates   
   and substition fails for the B overload because parameter type does   
   not match. Since substitution is not an error, the compiler should now   
   go on and consider the next function with the matching parameter and   
   come up with a single possible match.   
      
   Best regards,   
      Jens   
      
      
   --   
         [ 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