using decltype to distunguish the parameter-type of a std::function
Hendrik von Prince
prince@fh-coburg.de
Sat Mar 27 20:54:00 GMT 2010
Hi,
playing around with lambdas and std::function, i came into an
compiler error where i don't know if it is a bug or i am doing
something wrong or if it is just like suggested by the new
standard. The following minimal-example shows my issue:
#include <functional>
#include <vector>
template<class C>
void foo(C &c, std::function<void (decltype(*c.begin()))> fun)
{}
template<class C>
void bar(C &c, std::function<void (int)> fun)
{}
int main(int argc, char *argv[])
{
std::vector<int> vi;
bar(vi, [](int i){}); //ok
foo(vi, std::function<void (int)>([](int){})); //ok
foo(vi, [](int i){}); // error
return 0;
}
As i understand decltype, it should deduce the type of
the dereferenced iterator of the vector vi, which is
int. Thus, bar should have exactly the same signature
as foo and should also accept the lambda-expression
without explicitly cast into a function-object.
I am thankful of any helpful hint.
Hendrik
More information about the Gcc-help
mailing list