OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
variadic_to_vmpl_unit_test.hpp
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 
16 template <typename T>
17 struct F
18 {
20  typedef aggregate<T> type;
21 };
23 
25 template <typename arg0, typename T>
26 struct Ftwo
27 {
29  typedef aggregate<T> type;
30 };
32 
33 BOOST_AUTO_TEST_CASE( variadic_to_vmpl_test)
34 {
35  {
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 
53  }
54 
55  {
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]>>
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 
73  }
74 
75  {
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 
93  }
94 
95  {
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 
117  }
118 }
119 
120 BOOST_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_ */
aggregate< T > type
meta-function implementation
aggregate< T > type
meta-function implementation
boost::mpl::vector< boost::mpl::int_< id >... > type
construct an mpl vector from the variadic
v_transform_impl< H, first, last, exit_::value >::type type
generate the boost::fusion::vector apply H on each term
v_transform_two_impl< H, arg0, first, last, exit_::value >::type type
generate the boost::fusion::vector apply H on each term
[v_transform metafunction]
[v_transform metafunction]