using decltype to distunguish the parameter-type of a std::function

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux