Ticket #4228: test_map.cpp

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