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 40 41 42
| #include <iostream>
#include <string>
void f1()
{
std::cout<<"f1\n";
}
void f2()
{
std::cout<<"f2\n";
}
void f3()
{
std::cout<<"f3\n";
}
void f4(int i_)
{
std::cout<<"f4("<<i_<<")\n";
}
void f5(std::string str_)
{
std::cout<<"f5("<<str_<<")\n";
}
#include <functional>
#include <vector>
#include <algorithm>
int main()
{
typedef std::function<void ()> fonction_type;
std::vector<fonction_type> mes_fonctions={f1,f2,f3,std::bind(f4,1),std::bind(f5,"coucou")};
std::for_each(mes_fonctions.begin(),mes_fonctions.end(),[](fonction_type f_){f_();});
return 0;
} |
Partager