Why can's T be deduced? i.e. why do I get this error?
1 2
localpdb_capi.cc: In function ‘int probIterator(lua_State*)’:
localpdb_capi.cc:74: error: no matching function for call to ‘luaK_pushiter(lua_State*&, DB::ProblemIterator, DB::ProblemIterator, void (&)(lua_State*, boost::shared_ptr<DB::ProblemIterator>))’
boost::function (and std::function) is a type-erasing class: there is no direct connection between the type of std::function and the type of the object you're constructing it from.
Normal practice is to template on the functor type
1 2 3
template<class T, class F>
void luaK_pushiter( lua_State *l, T begin, T end, F wrapFunc )
{
Templating on the Functor type as you suggest works fine, but I still don't really understand what's going on. Do you know of a simple-ish article on argument deduction?
To put it simple, implicit conversions are not considered during deduction. They are considered during overload resolution, but to get there, the compiler needs to generate the list of overloads first.