1/*
2 * variadic_to_vmpl_unit_test.hpp
3 *
4 * Created on: Aug 19, 2015
5 * Author: i-bird
6 */
7
8#ifndef SRC_UTIL_VARIADIC_TO_VMPL_UNIT_TEST_HPP_
9#define SRC_UTIL_VARIADIC_TO_VMPL_UNIT_TEST_HPP_
10
11#include "util/variadic_to_vmpl.hpp"
12#include "util/util_debug.hpp"
13#include <typeinfo>
14
15//! [v_transform metafunction]
16template <typename T>
17struct F
18{
19 //! meta-function implementation
20 typedef aggregate<T> type;
21};
22//! [v_transform metafunction]
23
24//! [v_transform_two metafunction]
25template <typename arg0, typename T>
26struct Ftwo
27{
28 //! meta-function implementation
29 typedef aggregate<T> type;
30};
31//! [v_transform_two metafunction]
32
33BOOST_AUTO_TEST_CASE( variadic_to_vmpl_test)
34{
35 {
36 //! [v_transform usage]
37
38 typedef boost::mpl::vector<float,float,float[3]> bfv;
39
40 // tbvf is boost::fusion::vector<scalar<float>,scalar<float>,scalar<float[3]>>
41 typedef v_transform<F,bfv>::type tbfv;
42
43 bool val = std::is_same<boost::mpl::at<tbfv,boost::mpl::int_<0>>::type,aggregate<float>>::value;
44 BOOST_REQUIRE_EQUAL(val,true);
45
46 val = std::is_same<boost::mpl::at<tbfv,boost::mpl::int_<1>>::type,aggregate<float>>::value;
47 BOOST_REQUIRE_EQUAL(val,true);
48
49 val = std::is_same<boost::mpl::at<tbfv,boost::mpl::int_<2>>::type,aggregate<float[3]>>::value;
50 BOOST_REQUIRE_EQUAL(val,true);
51
52 //! [v_transform usage]
53 }
54
55 {
56 //! [v_transform_two usage]
57
58 typedef boost::mpl::vector<float,float,float[3]> bfv;
59
60 // tbvf is boost::fusion::vector<scalar<float>,scalar<float>,scalar<float[3]>>
61 typedef v_transform_two<Ftwo,float,bfv>::type tbfv;
62
63 bool val = std::is_same<boost::mpl::at<tbfv,boost::mpl::int_<0>>::type,aggregate<float>>::value;
64 BOOST_REQUIRE_EQUAL(val,true);
65
66 val = std::is_same<boost::mpl::at<tbfv,boost::mpl::int_<1>>::type,aggregate<float>>::value;
67 BOOST_REQUIRE_EQUAL(val,true);
68
69 val = std::is_same<boost::mpl::at<tbfv,boost::mpl::int_<2>>::type,aggregate<float[3]>>::value;
70 BOOST_REQUIRE_EQUAL(val,true);
71
72 //! [v_transform_two usage]
73 }
74
75 {
76 //! [to_boost_vmpl usage]
77
78 typedef to_boost_vmpl<1,4,5,9>::type bfv;
79
80 bool val = std::is_same<boost::mpl::at<bfv,boost::mpl::int_<0>>::type,boost::mpl::int_<1>>::value;
81 BOOST_REQUIRE_EQUAL(val,true);
82
83 val = std::is_same<boost::mpl::at<bfv,boost::mpl::int_<1>>::type,boost::mpl::int_<4>>::value;
84 BOOST_REQUIRE_EQUAL(val,true);
85
86 val = std::is_same<boost::mpl::at<bfv,boost::mpl::int_<2>>::type,boost::mpl::int_<5>>::value;
87 BOOST_REQUIRE_EQUAL(val,true);
88
89 val = std::is_same<boost::mpl::at<bfv,boost::mpl::int_<3>>::type,boost::mpl::int_<9>>::value;
90 BOOST_REQUIRE_EQUAL(val,true);
91
92 //! [to_boost_vmpl usage]
93 }
94
95 {
96 //! [vmpl_sum_constant usage]
97
98 typedef to_boost_vmpl<1,4,5,9>::type bfv;
99
100 typedef vmpl_sum_constant<5,bfv>::type vsc;
101
102 BOOST_REQUIRE_EQUAL(boost::mpl::size<vsc>::type::value,4);
103
104 bool val = std::is_same<boost::mpl::at<vsc,boost::mpl::int_<0>>::type,boost::mpl::int_<6>>::value;
105 BOOST_REQUIRE_EQUAL(val,true);
106
107 val = std::is_same<boost::mpl::at<vsc,boost::mpl::int_<1>>::type,boost::mpl::int_<9>>::value;
108 BOOST_REQUIRE_EQUAL(val,true);
109
110 val = std::is_same<boost::mpl::at<vsc,boost::mpl::int_<2>>::type,boost::mpl::int_<10>>::value;
111 BOOST_REQUIRE_EQUAL(val,true);
112
113 val = std::is_same<boost::mpl::at<vsc,boost::mpl::int_<3>>::type,boost::mpl::int_<14>>::value;
114 BOOST_REQUIRE_EQUAL(val,true);
115
116 //! [vmpl_sum_constant usage]
117 }
118}
119
120BOOST_AUTO_TEST_CASE( lin_vmpl_test )
121{
122 typedef boost::mpl::vector<boost::mpl::int_<16>,boost::mpl::int_<17>,boost::mpl::int_<18>> vector;
123
124 typedef boost::mpl::vector<boost::mpl::int_<1>,boost::mpl::int_<2>,boost::mpl::int_<3>> offset;
125
126 int lino = Lin_vmpl_off<vector,offset>(0,0,0);
127 int lin = Lin_vmpl<vector>(0,0,0);
128
129 BOOST_REQUIRE_EQUAL(lino,1+2*16+3*16*17);
130 BOOST_REQUIRE_EQUAL(lin,0);
131
132 lino = Lin_vmpl_off<vector,offset>(0,1,0);
133 lin = Lin_vmpl<vector>(0,1,0);
134
135 BOOST_REQUIRE_EQUAL(lino,1+3*16+3*16*17);
136 BOOST_REQUIRE_EQUAL(lin,16);
137
138 lino = Lin_vmpl_off<vector,offset>(0,0,1);
139 lin = Lin_vmpl<vector>(0,0,1);
140
141 BOOST_REQUIRE_EQUAL(lino,1+2*16+4*16*17);
142 BOOST_REQUIRE_EQUAL(lin,16*17);
143}
144
145#endif /* SRC_UTIL_VARIADIC_TO_VMPL_UNIT_TEST_HPP_ */
146