5

How do I turn below function into a typedef?

auto fn = [&] (int x) { doSomething(x, 3); }
linquize
  • 19,828
  • 10
  • 59
  • 83

3 Answers3

7

You can use decltype to get the exact type:

  auto fn = [&] (int x) { doSomething(x, 3); };
  using lambda_type = decltype(fn);

But if you merely want to know a compatible, more general type, say for passing the lambda as argument to another function, you can use std::function<void(int)> (as Joachim mentions).

mavam
  • 12,242
  • 10
  • 53
  • 87
3

How about

using my_function_type = std::function<void(int)>;
Some programmer dude
  • 400,186
  • 35
  • 402
  • 621
1
typedef std::function<void(int)> my_function_type;

Works in VS2012

linquize
  • 19,828
  • 10
  • 59
  • 83