This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
using decltype to distunguish the parameter-type of a std::function
- From: "Hendrik von Prince" <prince at fh-coburg dot de>
- To: "gcc-help at gcc dot gnu dot org" <gcc-help at gcc dot gnu dot org>
- Date: Sat, 27 Mar 2010 16:32:31 +0100
- Subject: using decltype to distunguish the parameter-type of a std::function
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