1 |
|
---|
2 | #include "boost/fusion/adapted/mpl.hpp"
|
---|
3 | #include "boost/fusion/container/map/convert.hpp"
|
---|
4 | #include "boost/fusion/sequence/intrinsic/at.hpp"
|
---|
5 | #include "boost/fusion/support/pair.hpp"
|
---|
6 | #include "boost/fusion/view/transform_view.hpp"
|
---|
7 |
|
---|
8 | using namespace boost;
|
---|
9 |
|
---|
10 | struct TestType0 : mpl::int_<0> {};
|
---|
11 | struct TestType1 : mpl::int_<1> {};
|
---|
12 | struct TestType2 : mpl::int_<2> {};
|
---|
13 | struct TestType3 : mpl::int_<3> {};
|
---|
14 | struct TestType4 : mpl::int_<4> {};
|
---|
15 | struct TestType5 : mpl::int_<5> {};
|
---|
16 | struct TestType6 : mpl::int_<6> {};
|
---|
17 | struct TestType7 : mpl::int_<7> {};
|
---|
18 | struct TestType8 : mpl::int_<8> {};
|
---|
19 | struct TestType9 : mpl::int_<9> {};
|
---|
20 |
|
---|
21 |
|
---|
22 | typedef fusion::vector10
|
---|
23 | <
|
---|
24 | TestType0,
|
---|
25 | TestType1,
|
---|
26 | TestType2,
|
---|
27 | TestType3,
|
---|
28 | TestType4,
|
---|
29 | TestType5,
|
---|
30 | TestType6,
|
---|
31 | TestType7,
|
---|
32 | TestType8
|
---|
33 | > MainTypes;
|
---|
34 |
|
---|
35 |
|
---|
36 | struct OddWidget { int dummy_; };
|
---|
37 | struct EvenWidget { int dummy_; };
|
---|
38 |
|
---|
39 | struct Transformer
|
---|
40 | {
|
---|
41 | template <typename Sig>
|
---|
42 | struct result;
|
---|
43 |
|
---|
44 | template <typename T>
|
---|
45 | struct result<Transformer( T )> : fusion::pair<T, mpl::if_c<T::value % 2, OddWidget, EvenWidget>::type> {};
|
---|
46 | };
|
---|
47 |
|
---|
48 |
|
---|
49 | int main()
|
---|
50 | {
|
---|
51 | typedef boost::fusion::transform_view
|
---|
52 | <
|
---|
53 | MainTypes,
|
---|
54 | Transformer
|
---|
55 | > WidgetsView;
|
---|
56 |
|
---|
57 | typedef typename boost::fusion::result_of::as_map
|
---|
58 | <
|
---|
59 | WidgetsView
|
---|
60 | >::type WidgetContainer;
|
---|
61 |
|
---|
62 | WidgetContainer widgets;
|
---|
63 | return fusion::at_key<TestType4>( widgets ).dummy_;
|
---|
64 | }
|
---|