Alex Rivera | Logout

Creating a map of lambdas in C++

Asked 2012-04-24T08:05:45.547
8

How can I describe a map of lambda? I want to have a map of lambda which will be called on event (just as a simple callback). The lambda type is constant.

Edit
Report

1 Answer

20

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

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

Assuming that you index the callbacks using an unsigned int, the above map stores functions that take in two int and return an int.

answered 2012-04-24T08:08:18.650

Your Answer