1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
| #include <functional>
#include <map>
#include <iostream>
#include <algorithm>
void function_1()
{
std::cout<<"1\n";
}
void function_2()
{
std::cout<<"2\n";
}
void function_3()
{
std::cout<<"3\n";
}
int main()
{
enum key {
key_1,
key_2,
key_3
};
std::map<key,std::function<void(void)>> const my_map={
{key_1, function_1}
,{key_2, function_2}
,{key_3, function_3}
};
std::for_each(my_map.begin(),my_map.end(),[](std::pair<const key,std::function<void(void)> > const&par )
{
par.second();
}
);
} |
Partager