Ticket #4228: test_vector.cpp

File test_vector.cpp, 1.7 KB (added by Domagoj Šarić, 12 years ago)
Line 
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
7using namespace boost;
8
9struct TestType0 : mpl::int_<0> {};
10struct TestType1 : mpl::int_<1> {};
11struct TestType2 : mpl::int_<2> {};
12struct TestType3 : mpl::int_<3> {};
13struct TestType4 : mpl::int_<4> {};
14struct TestType5 : mpl::int_<5> {};
15struct TestType6 : mpl::int_<6> {};
16struct TestType7 : mpl::int_<7> {};
17struct TestType8 : mpl::int_<8> {};
18struct TestType9 : mpl::int_<9> {};
19
20
21typedef 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
35struct OddWidget { int dummy_; };
36struct EvenWidget { int dummy_; };
37
38struct 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
48int 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}