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