This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]