/* * reftest.cpp * * Created on: Apr 3, 2011 * Author: joe */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace boost; using namespace boost::fusion; using boost::fusion::vector; namespace functors { // A functor returns the dot product of two sequences. Presumes that the return type is the // type of the first element of the first sequence argument. struct vector_dot_product_impl { template struct result { // Presume that the return type is the type of the first element // of the first sequence argument. typedef typename boost::fusion::result_of::value_at >::type type; }; template typename result::type operator()(V1 v1, V2 v2) const { using boost::phoenix::arg_names::_1; using boost::phoenix::arg_names::_2; using boost::fusion::fold; using boost::fusion::transform; return fold(transform(v1, v2, _1 * _2), 0.0, _1 + _2); } }; boost::phoenix::function const vector_dot_product; } // namespace functors int main() { typedef vector int3; typedef vector int2; int3 i3a = make_vector(1,2,3); int3 i3b = make_vector(4,5,6); using boost::phoenix::arg_names::_1; using boost::phoenix::arg_names::_2; std::cout << "DOT: " << functors::vector_dot_product(_1, _2)(i3a, i3b) << std::endl; }