You don’t need a handcrafted function object, just use std::function
, to which lambda functions are convertible:
This example returns the integer identity function:
std::function<int (int)> retFun() {
return [](int x) { return x; };
}
More Related Contents:
- Declaring lambda with int type not working [closed]
- How to convert a lambda to an std::function using templates
- Inferring the call signature of a lambda or arbitrary callable for “make_function”
- Why can’t C++11 move a noncopyable functor to a std::function?
- Using generic std::function objects with member functions in one class
- C++ lambda with captures as a function pointer
- Move capture in lambda
- Passing capturing lambda as function pointer
- What is the type of lambda when deduced with “auto” in C++11?
- How is std::function implemented?
- Why can lambdas be better optimized by the compiler than plain functions?
- Bind Vs Lambda?
- C++0x lambda capture by value always const?
- C++11 lambda implementation and memory model
- Can lambda functions be templated?
- Error: variable “cannot be implicitly captured because no default capture mode has been specified”
- Lambda capture as const reference?
- why do lambda functions in c++11 not have function types?
- Why can’t I create a vector of lambdas (of the same type) in C++11?
- Why can’t I capture this by-reference (‘&this’) in lambda?
- Lambda expressions as class template parameters
- How to immediately invoke a C++ lambda?
- Do c++11 lambdas capture variables they don’t use?
- How do static variables in lambda function objects work?
- Lambdas and capture by reference local variables : Accessing after the scope
- How can I pass a C++ lambda to a C-callback that expects a function pointer and a context?
- Specializing a template on a lambda in C++0x
- Can using a lambda in header files violate the ODR?
- Can the ‘type’ of a lambda expression be expressed?
- When can we omit the return type in a C++11 lambda?