What is this type?

closed account (Sw07fSEw)
I've read about function pointers and now I'm coming across lambda expressions in my C++ primer book. It's mentioned that any callable object can be passed to an algorithm.

In one of the examples, the author uses the following code to declare a callable object:

1
2
  auto f = [] { return 42; };
  std::cout << f() << std::endl;


What type is auto representing in this example?
Last edited on
> What type is auto representing in this example?

a pointer to a lambda function
Last edited on
closed account (Sw07fSEw)
Right, let me restate my question, how I would express the type of f instead of using auto?

From what I've learned so far, the lambda expression has a capture list, parameter list, return type and function body.

I.e. [capture list] (parameter list) -> return type { function body }

How do I express that on the left hand side of the assignment operator?

1
2
[] int*{} f = [] { return 42; }; //this won't compile, but I can't think of how else to write the lefthand side. 
//I omitted the parameter list because it appears to be optional if it's empty, which in this case, it is.  
Last edited on
Topic archived. No new replies allowed.