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 43 44 45 46 47 48
| #include <functional>
#include <iostream>
#include <string>
#include <boost/fusion/include/map.hpp>
#include <boost/fusion/include/make_map.hpp>
#include <boost/fusion/include/at_key.hpp>
void function_1(int i)
{
std::cout<<"function_1("<<i<<")\n";
}
void function_2(double d)
{
std::cout<<"function_2("<<d<<")\n";
}
void function_3(std::string s)
{
std::cout<<"function_3("<<s<<")\n";
}
namespace
{
struct key_1;
struct key_2;
struct key_3;
typedef std::function<void (int i)> type_fun_1;
typedef std::function<void (double d)> type_fun_2;
typedef std::function <void (std::string s)> type_fun_3;
typedef boost::fusion::map<
boost::fusion::pair<key_1,type_fun_1>
,boost::fusion::pair<key_2,type_fun_2>
,boost::fusion::pair<key_3,type_fun_3>
> type_map_operations;
}
int main()
{
type_map_operations const operations = boost::fusion::make_map<key_1,key_2,key_3,type_fun_1,type_fun_2,type_fun_3>(
function_1,function_2,function_3);
boost::fusion::at_key<key_1>(operations)(1);
boost::fusion::at_key<key_2>(operations)(2.4);
boost::fusion::at_key<key_3>(operations)("tutu");
return 0;
} |
Partager