29,217d28 < < //this should probably go to boost/tuple/tuple.hpp < namespace boost { namespace tuples{ < < template < struct element > { < typedef typename std::tuple_element >::type type; < }; < < }} < < < //helper classes to work with std::tuple < namespace helper { < < //get head of std::tuple < template struct head{ < typedef decltype( std::get<0>( std::declval() ) ) type; < }; < < //get tail of std::tuple < template struct tail{ typedef std::tuple<> type; }; < < //specialisations allow for perfect forwarding < template < struct tail< std::tuple& >{ < < typedef typename std::conditional< < sizeof...(Args) == 0, < std::tuple<>, < std::tuple& < >::type type; < }; < < template < struct tail< std::tuple const& >{ < typedef typename std::conditional< < sizeof...(Args) == 0, < std::tuple<>, < std::tuple const& < >::type type; < }; < < template < struct tail< std::tuple&& >{ < typedef typename std::conditional< < sizeof...(Args) == 0, < std::tuple<>, < std::tuple && < >::type type; < }; < < < //concatenate 2 tuples < template struct concat { < < typedef decltype( std::tuple_cat(std::declval(), < std::declval()) ) type; < < inline static type call(Tuple1&& t1, Tuple2&& t2) { < return std::tuple_cat( std::forward(t1), < std::forward(t2) ); < } < }; < < < //wrap mpl meta function to allow return type derivation via decltype < template < struct wrap { < typedef typename boost::mpl::lambda::type Lambda; < < < template < struct result { < typedef typename Lambda::template apply::type type; < }; < < template < typename result::type operator()(Args...) < { < return std::declval< typename result::type >(); < } < }; < < < < // Apply unary functor to each member of tuple < template > < struct apply < { < typedef typename std::result_of::type)>::type < result_type; < < typedef apply< F, < typename tail::type, < typename concat >::type > next; < < typedef typename next::type type; < < < //function to implemnt the apply functionality < template < static typename apply::type < call(F f, T&& in) < { < return concat < < std::tuple, < typename apply< < F, < typename tail::type < >::type < >::call( std::tuple( f( std::get( std::forward(in) ))), < next::template call(f, std::forward(in) ) ); < } < }; < < //Specialisation for empty tuples < template < struct apply< F, std::tuple<>, Output> < { < typedef Output type; < < template < inline static typename std::tuple<> call(F, T) { return std::tuple<>(); } < }; < < //Successively apply binary operator to tuple members < template < struct accumulate < { < typedef typename std::result_of::type, < State)>::type result_type; < < < typedef accumulate< typename tail::type, < Op, < result_type > next; < < typedef typename next::type type; < < template < static type call(T&& in, Op op, State state) < { < return next::template call(std::forward(in), < op, < op( std::get(std::forward(in)), < state ) ); < } < };//accumulate < < //Specialisation for empty tuple < template < struct accumulate< std::tuple<>, Op, State> < { < typedef State type; < < template < static type call(T, Op, State state) { return state; } < }; < < < //for each specialisation for std::tuples < template < inline typename std::enable_if< I == std::tuple_size::value, F>::type < for_each(Tuple&, F f){ return f; } < < template < inline typename std::enable_if< I != std::tuple_size::value, F>::type < for_each(Tuple& t, F f) < { < f( std::get(t) ); < return for_each(t, f); < } < < < < }//namespace helper < < < < < < 325,348d135 < < // Specialisation for std::tuple < template < struct tuple_meta_transform< std::tuple, UnaryMetaFun> < { < typedef typename helper::apply< helper::wrap, < std::tuple const& >::type type; < }; < < // Specialisation for std::pair < template < struct tuple_meta_transform< std::pair, UnaryMetaFun> < { < typedef std::pair< < typename mpl::apply1< < typename mpl::lambda::type < , T1 < >::type < , typename mpl::apply1< < typename mpl::lambda::type < , T1 < >::type < > type; < }; 400,435d186 < // specialisation for std::tuples < template < struct tuple_meta_accumulate< std::tuple, < BinaryMetaFun, < StartType > < { < typedef typename helper::accumulate< < std::tuple, < helper::wrap, < StartType < >::type type; < }; < < // specialisation for std::pair < template< < typename T1 < , typename T2 < , class BinaryMetaFun < , typename StartType < > < struct tuple_meta_accumulate_impl< std::pair, < BinaryMetaFun, < StartType > < { < typedef typename mpl::apply2< < typename mpl::lambda::type, < mpl::identity, < typename mpl::apply2< < typename mpl::lambda::type, < T1, < T2 < >::type < >::type type; < }; < < 469,470c220,224 < namespace detail{ < --- > template > tuples::null_type BOOST_TUPLE_ALGO(tuple_transform) > (tuples::null_type const&, Fun BOOST_TUPLE_ALGO_TERMINATOR) > { return tuples::null_type(); } > 472,476c226,236 < struct tuple_transform_impl { < < static typename tuple_meta_transform::type < BOOST_TUPLE_ALGO(call)(const Tuple& t, Fun f BOOST_TUPLE_ALGO_RECURSE ) < { --- > typename tuple_meta_transform< > Tuple > , Fun > >::type > > BOOST_TUPLE_ALGO(tuple_transform)( > const Tuple& t, > Fun f > BOOST_TUPLE_ALGO_RECURSE > ) > { 481,492c241,250 < < return tuples::cons< < BOOST_DEDUCED_TYPENAME mpl::apply1< < Fun, BOOST_DEDUCED_TYPENAME Tuple::head_type < >::type < , transformed_tail_type < >( < f(boost::tuples::get<0>(t)), < tuple_transform_impl::call( t.get_tail(), f) < ); < } --- > > return tuples::cons< > BOOST_DEDUCED_TYPENAME mpl::apply1< > Fun, BOOST_DEDUCED_TYPENAME Tuple::head_type > >::type > , transformed_tail_type > >( > f(boost::tuples::get<0>(t)), tuple_transform(t.get_tail(), f) > ); > } 495,499c253,265 < static typename tuple_meta_transform::type < call(const Tuple& t, Fun f) < { < return call_impl(t, f, 1); < } --- > template > typename tuple_meta_transform< > Tuple > , Fun > >::type > > tuple_transform( > const Tuple& t, > Fun f > ) > { > return tuple_transform_impl(t, f, 1); > } 501,542d266 < };//tuple_transform_impl < < < template < struct tuple_transform_impl { < < static tuples::null_type < BOOST_TUPLE_ALGO(call)(tuples::null_type const&, < Fun BOOST_TUPLE_ALGO_TERMINATOR) < { < return tuples::null_type(); < } < }; < < < // specialisation for std::tuples < template < struct tuple_transform_impl , Fun> { < < template < inline static < typename tuple_meta_transform< std::tuple, Fun>::type < call(T&& t, Fun f ) < { < return helper::apply::template call<0>(f, std::forward(t) ); < } < }; < < //specialisation for std::pair < template < struct tuple_transform_impl< std::tuple, Fun> { < < static typename tuple_meta_transform, Fun>::type < call(const std::tuple& t, Fun f) < { < typedef typename tuple_meta_transform, Fun>::type < return_type; < < return return_type( f(t.first), f(t.second) ); < } < }; < 545a270,277 > template > Fun BOOST_TUPLE_ALGO(tuple_for_each)( > tuples::null_type > , Fun f BOOST_TUPLE_ALGO_TERMINATOR > ) > { return f; } > > 547,549c279,282 < struct tuple_for_each_impl { < static Fun BOOST_TUPLE_ALGO(call)( Tuple& t, Fun f BOOST_TUPLE_ALGO_RECURSE) < { --- > Fun BOOST_TUPLE_ALGO(tuple_for_each)( > Tuple& t > , Fun f BOOST_TUPLE_ALGO_RECURSE) > { 551,554c284,286 < return tuple_for_each_impl::call( t.get_tail(), f); < } < --- > return tuple_for_each(t.get_tail(), f); > } > 556c288,293 < static Fun call(Tuple& t, Fun f) --- > template > Fun > tuple_for_each( > Tuple& t, > Fun f > ) 558c295 < return call_impl(t, f, 1); --- > return tuple_for_each_impl(t, f, 1); 561,595d297 < }; < < template < struct tuple_for_each_impl { < inline static Fun call( tuples::null_type, < Fun f BOOST_TUPLE_ALGO_TERMINATOR) < { < return f; < } < }; < < < // for_each algorithm for std::tuple < template < struct tuple_for_each_impl< std::tuple, Fun> { < < inline static Fun call(std::tuple& t, Fun f) < { < return helper::for_each(t, f); < } < < }; < < // for_each algorithm for std::pair < template < struct tuple_for_each_impl< std::pair, Fun> { < < inline static Fun call(std::pair& t, Fun f) < { < f(t.first); < f(t.second); < return f; < } < < }; 602,656c304,305 < template < struct tuple_equal_impl{ < static bool call(const Tuple1& t1, const Tuple2& t2){ < return t1.get_head() == t2.get_head() && < tuple_equal(t1.get_tail(), t2.get_tail()); < } < }; < < template<> < struct tuple_equal_impl { < inline static bool call(tuples::null_type, tuples::null_type){ < return true; < } < }; < < // Equality of std::tuples. < template < struct tuple_equal_impl< std::tuple, std::tuple > { < < inline static bool call( const std::tuple& t1, < const std::tuple& t2 ) < { < return t1 == t2; < } < }; < < // Equality of std::pair < template < struct tuple_equal_impl< std::pair, std::pair > { < < inline static bool call( const std::pair& t1, < const std::pair& t2 ) < { < return t1 == t2; < } < }; < < }//namespace detail < < < //Forward template functions to respective implementations < < template < inline typename tuple_meta_transform::type < tuple_transform(const Tuple& t, Fun f) < { < return detail::tuple_transform_impl::call(t, f); < } < < < template < inline Fun tuple_for_each(Tuple& t, Fun f) < { < return detail::tuple_for_each_impl::call(t, f); < } --- > inline bool tuple_equal(tuples::null_type, tuples::null_type) > { return true; } 659c308,311 < inline bool tuple_equal(Tuple1 const& t1, Tuple2 const& t2) --- > bool tuple_equal( > Tuple1 const& t1, > Tuple2 const& t2 > ) 661c313,314 < return detail::tuple_equal_impl::call(t1, t2); --- > return t1.get_head() == t2.get_head() && > tuple_equal(t1.get_tail(), t2.get_tail());