19 #define BOOST_FUSION_INVOKE_MAX_ARITY 10 29 #include "pinocchio/tools/timer.hpp" 32 #include <boost/test/unit_test.hpp> 33 #include <boost/utility/binary.hpp> 38 TestObj() : i(0) { std::cout <<
"Test()" << std::endl; }
39 TestObj(
int i) : i(i) { std::cout <<
"Test(int)" << std::endl; }
40 TestObj(
const TestObj& clone) : i(clone.i) { std::cout <<
"Test(clone)" << std::endl; }
48 const D&
derived()
const {
return static_cast<const D&
> (*this); }
50 void f() {
static_cast<D*
>(
this)->
f(); }
51 int g() {
return static_cast<D*
>(
this)->
g(); }
52 int h(
const double &
x) {
return static_cast<D*
>(
this)->
h(x); }
53 int hh(
const double &
x,
const int & y,
const Eigen::MatrixXd & z,
const TestObj & a) {
return static_cast<D*
>(
this)->
hh(x,y,z,a); }
58 void f() { std::cout <<
"f()" << std::endl; }
59 int g() { std::cout <<
"g()" << std::endl;
return 1; }
60 int h(
const double &
x) { std::cout <<
"h(" << x <<
")" << std::endl;
return 2; }
61 int hh(
const double &
x,
const int & y,
const Eigen::MatrixXd & z,
const TestObj & )
62 { std::cout <<
"hh(" << x <<
"," << y <<
"," << z <<
",a)" << std::endl;
return 3; }
67 void f() { std::cout <<
"f()" << std::endl; }
68 int g() { std::cout <<
"g()" << std::endl;
return 1; }
69 int h(
const double &
x) { std::cout <<
"h(" << x <<
")" << std::endl;
return 2; }
70 int hh(
const double &
x,
const int & y,
const Eigen::MatrixXd & z,
const TestObj & )
71 { std::cout <<
"hh(" << x <<
"," << y <<
"," << z <<
",a)" << std::endl;
return 3; }
89 #include <boost/variant.hpp> 92 #include <boost/fusion/include/sequence.hpp> 93 #include <boost/fusion/include/make_vector.hpp> 94 #include <boost/fusion/include/next.hpp> 95 #include <boost/fusion/include/invoke.hpp> 96 #include <boost/fusion/view/joint_view.hpp> 97 #include <boost/fusion/include/joint_view.hpp> 98 #include <boost/fusion/algorithm.hpp> 99 #include <boost/fusion/container.hpp> 104 struct Launcher :
public boost::static_visitor<int>
107 typedef bf::vector<
const double &,
const int &,
const Eigen::MatrixXd &,
108 const Eigen::MatrixXd &,
const Eigen::MatrixXd &,
const TestObj &>
Args;
116 return bf::invoke(&Launcher::algo<D>,bf::push_front(args,boost::ref(dref)));
121 return boost::apply_visitor(
Launcher(args),crtp );
125 static int algo(
CRTPBase<D> & crtp,
const double &
x,
const int & y,
const Eigen::MatrixXd & z,
126 const Eigen::MatrixXd & ,
const Eigen::MatrixXd & ,
const TestObj & a)
128 return crtp.
hh(x,y,z,a);
134 template<
typename T,
typename V>
136 append(
T const&
t,
V const&
v) {
return push_front(v,t); }
138 template<
typename T1,
typename T2,
typename V>
140 append2(T1
const& t1,T2
const& t2,V
const& v) {
return push_front(push_front(v,t2),t1); }
152 BOOST_AUTO_TEST_SUITE ( BOOST_TEST_MODULE )
165 Eigen::MatrixXd::Zero(3,3),
TestObj(1)) );
168 bf::vector<int&> arg = bf::make_vector(boost::ref(j));
170 bf::vector<double &,int &> arg1 =
bf::append(boost::ref(k),arg);
171 bf::vector<int &,double &,int &> arg11 =
bf::append(boost::ref(
i),arg1);
173 bf::vector<int &,double &,int &> arg2 =
bf::append2(boost::ref(
i),boost::ref(k),arg);
177 BOOST_AUTO_TEST_SUITE_END ()
boost::variant< CRTPDerived, CRTPDerived2 > CRTPVariant
result_of::push_front< V const, T >::type append(T const &t, V const &v)
Append the element T at the front of boost fusion vector V.
int hh(const double &x, const int &y, const Eigen::MatrixXd &z, const TestObj &)
static int algo(CRTPBase< D > &crtp, const double &x, const int &y, const Eigen::MatrixXd &z, const Eigen::MatrixXd &, const Eigen::MatrixXd &, const TestObj &a)
TestObj(const TestObj &clone)
BOOST_AUTO_TEST_CASE(test_fusion)
static int run(CRTPVariant &crtp, Args args)
bf::vector< const double &, const int &, const Eigen::MatrixXd &, const Eigen::MatrixXd &, const Eigen::MatrixXd &, const TestObj & > Args
const D & derived() const
int hh(const double &x, const int &y, const Eigen::MatrixXd &z, const TestObj &a)
result_of::push_front< typename result_of::push_front< V const, T2 >::type const, T1 >::type append2(T1 const &t1, T2 const &t2, V const &v)
int hh(const double &x, const int &y, const Eigen::MatrixXd &z, const TestObj &)