From c16dc354a9a18b1950cdbd89f861895058ef8c93 Mon Sep 17 00:00:00 2001 From: Olivier Parcollet Date: Sat, 27 Jul 2013 23:00:32 +0200 Subject: [PATCH] tuple tools : generalize apply_on_zip to accept && --- triqs/utility/tuple_tools.hpp | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/triqs/utility/tuple_tools.hpp b/triqs/utility/tuple_tools.hpp index 538cbd07..bb6a61db 100644 --- a/triqs/utility/tuple_tools.hpp +++ b/triqs/utility/tuple_tools.hpp @@ -109,19 +109,19 @@ namespace triqs { namespace tuple { * t1, t2 two tuples of the same size * Returns : [f(i,j) for i,j in zip(t1,t2)] */ - template struct apply_on_zip_impl { - template - auto operator()(F && f, T1 const & t1, T2 const & t2, Args && ... args) - DECL_AND_RETURN( apply_on_zip_impl()(std::forward(f),t1, t2, f(std::get(t1),std::get(t2)), std::forward(args)...)); + template struct apply_on_zip_impl { + template + auto operator()(F && f, T1 && t1, T2 && t2, Args && ... args) + DECL_AND_RETURN( apply_on_zip_impl()(std::forward(f),std::forward(t1), std::forward(t2), f(std::get(t1),std::get(t2)), std::forward(args)...)); }; - template struct apply_on_zip_impl<-1,T1,T2> { - template - auto operator()(F && f, T1 const & t1, T2 const & t2, Args && ... args) DECL_AND_RETURN( std::make_tuple(std::forward(args)...)); + template<> struct apply_on_zip_impl<-1> { + template + auto operator()(F && f, T1 && t1, T2 && t2, Args && ... args) DECL_AND_RETURN( std::make_tuple(std::forward(args)...)); }; template - auto apply_on_zip (F && f,T1 const & t1, T2 const & t2) DECL_AND_RETURN( apply_on_zip_impl::value-1,T1,T2>()(std::forward(f),t1,t2)); + auto apply_on_zip (F && f,T1 && t1, T2 && t2) DECL_AND_RETURN( apply_on_zip_impl::type>::value-1>()(std::forward(f),std::forward(t1),std::forward(t2))); /** * apply_on_tuple(f, t1,t2,t3) @@ -129,19 +129,20 @@ namespace triqs { namespace tuple { * t1, t2 two tuples of the same size * Returns : [f(i,j) for i,j in zip(t1,t2)] */ - template struct apply_on_zip3_impl { - template - auto operator()(F && f, T1 const & t1, T2 const & t2, T3 const & t3, Args && ... args) - DECL_AND_RETURN( apply_on_zip3_impl()(std::forward(f),t1, t2, t3, f(std::get(t1),std::get(t2),std::get(t3)), std::forward(args)...)); + template struct apply_on_zip3_impl { + template + auto operator()(F && f, T1 && t1, T2 && t2, T3 && t3, Args && ... args) + DECL_AND_RETURN( apply_on_zip3_impl()(std::forward(f),std::forward(t1), std::forward(t2), std::forward(t3), + f(std::get(t1),std::get(t2),std::get(t3)), std::forward(args)...)); }; - template struct apply_on_zip3_impl<-1,T1,T2,T3> { - template - auto operator()(F && f, T1 const & t1, T2 const & t2, T3 const & t3, Args && ... args) DECL_AND_RETURN( std::make_tuple(std::forward(args)...)); + template<> struct apply_on_zip3_impl<-1> { + template + auto operator()(F && f, T1 && t1, T2 && t2, T3 && t3, Args && ... args) DECL_AND_RETURN( std::make_tuple(std::forward(args)...)); }; template - auto apply_on_zip3 (F && f,T1 const & t1, T2 const & t2, T3 const & t3) DECL_AND_RETURN( apply_on_zip3_impl::value-1,T1,T2,T3>()(std::forward(f),t1,t2,t3)); + auto apply_on_zip3 (F && f,T1 && t1, T2 && t2, T3 && t3) DECL_AND_RETURN( apply_on_zip3_impl::type>::value-1>()(std::forward(f),std::forward(t1),std::forward(t2),std::forward(t3))); /** * fold(f, t1, init)