Creating a lambdas map in C ++

How can I describe a lambda map? I want to have a lambda map that will be triggered by an event (as a simple callback). The lambda type is permanent.

+5
source share
1 answer

Use the title <functional>and class of the template std::function. This allows you to specify function objects with a fixed method signature.

std::map< unsigned int, std::function<int(int,int)> > callbackMap;

Assuming you index callbacks with unsigned int, the above map stores functions that take two intand return int.

+15
source

All Articles