With that in mind, it made me curious ifThe type of a lambda function is a unique anonymous functor type for every lambda function. Two separate lambdas that have the exact same definition in the exact same scope will have two separate types. As such, trying to get at the exact type of a lambda function is an exercise in futility. Just store the std::function by value.
auto lines = []() { cout<<"- - - - - -"<<endl; };
auto dots = []() { cout<<". . . . . ."<<endl; };
lines = dots;
works. I don't have a compiler on my current machine to test if the assignment gives a compile time error. [edit]
Got that sooner than I thought I would. For my little test, the type of lines is const main()::<lambda()>& and the assignment generates a compile time error.
However, a normal function pointer worked:
#include <iostream>
#include <functional>
typedef void (*function) ();
int main()
{
function lines = []() { std::cout << " - - - - - " << std::endl; };
auto dots = []() { std::cout << " . . . . . " << std::endl; };
lines = dots;
lines();
dots();
}
But yes, I would just go with a std::function.