mirror of
https://github.com/triqs/dft_tools
synced 2024-12-26 06:14:14 +01:00
tuple tools : generalize apply_on_zip to accept &&
This commit is contained in:
parent
65bdc65da1
commit
c16dc354a9
@ -109,19 +109,19 @@ namespace triqs { namespace tuple {
|
|||||||
* t1, t2 two tuples of the same size
|
* t1, t2 two tuples of the same size
|
||||||
* Returns : [f(i,j) for i,j in zip(t1,t2)]
|
* Returns : [f(i,j) for i,j in zip(t1,t2)]
|
||||||
*/
|
*/
|
||||||
template<int pos, typename T1, typename T2> struct apply_on_zip_impl {
|
template<int pos> struct apply_on_zip_impl {
|
||||||
template<typename F, typename ... Args>
|
template<typename F, typename T1, typename T2, typename ... Args>
|
||||||
auto operator()(F && f, T1 const & t1, T2 const & t2, Args && ... args)
|
auto operator()(F && f, T1 && t1, T2 && t2, Args && ... args)
|
||||||
DECL_AND_RETURN( apply_on_zip_impl<pos-1,T1,T2>()(std::forward<F>(f),t1, t2, f(std::get<pos>(t1),std::get<pos>(t2)), std::forward<Args>(args)...));
|
DECL_AND_RETURN( apply_on_zip_impl<pos-1>()(std::forward<F>(f),std::forward<T1>(t1), std::forward<T2>(t2), f(std::get<pos>(t1),std::get<pos>(t2)), std::forward<Args>(args)...));
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename T1, typename T2> struct apply_on_zip_impl<-1,T1,T2> {
|
template<> struct apply_on_zip_impl<-1> {
|
||||||
template<typename F, typename ... Args>
|
template<typename F, typename T1, typename T2, typename ... Args>
|
||||||
auto operator()(F && f, T1 const & t1, T2 const & t2, Args && ... args) DECL_AND_RETURN( std::make_tuple(std::forward<Args>(args)...));
|
auto operator()(F && f, T1 && t1, T2 && t2, Args && ... args) DECL_AND_RETURN( std::make_tuple(std::forward<Args>(args)...));
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename F, typename T1, typename T2>
|
template<typename F, typename T1, typename T2>
|
||||||
auto apply_on_zip (F && f,T1 const & t1, T2 const & t2) DECL_AND_RETURN( apply_on_zip_impl<std::tuple_size<T1>::value-1,T1,T2>()(std::forward<F>(f),t1,t2));
|
auto apply_on_zip (F && f,T1 && t1, T2 && t2) DECL_AND_RETURN( apply_on_zip_impl<std::tuple_size<typename std::remove_reference<T1>::type>::value-1>()(std::forward<F>(f),std::forward<T1>(t1),std::forward<T2>(t2)));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* apply_on_tuple(f, t1,t2,t3)
|
* apply_on_tuple(f, t1,t2,t3)
|
||||||
@ -129,19 +129,20 @@ namespace triqs { namespace tuple {
|
|||||||
* t1, t2 two tuples of the same size
|
* t1, t2 two tuples of the same size
|
||||||
* Returns : [f(i,j) for i,j in zip(t1,t2)]
|
* Returns : [f(i,j) for i,j in zip(t1,t2)]
|
||||||
*/
|
*/
|
||||||
template<int pos, typename T1, typename T2, typename T3> struct apply_on_zip3_impl {
|
template<int pos> struct apply_on_zip3_impl {
|
||||||
template<typename F, typename ... Args>
|
template<typename F, typename T1, typename T2, typename T3, typename ... Args>
|
||||||
auto operator()(F && f, T1 const & t1, T2 const & t2, T3 const & t3, Args && ... args)
|
auto operator()(F && f, T1 && t1, T2 && t2, T3 && t3, Args && ... args)
|
||||||
DECL_AND_RETURN( apply_on_zip3_impl<pos-1,T1,T2,T3>()(std::forward<F>(f),t1, t2, t3, f(std::get<pos>(t1),std::get<pos>(t2),std::get<pos>(t3)), std::forward<Args>(args)...));
|
DECL_AND_RETURN( apply_on_zip3_impl<pos-1>()(std::forward<F>(f),std::forward<T1>(t1), std::forward<T2>(t2), std::forward<T3>(t3),
|
||||||
|
f(std::get<pos>(t1),std::get<pos>(t2),std::get<pos>(t3)), std::forward<Args>(args)...));
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename T1, typename T2, typename T3> struct apply_on_zip3_impl<-1,T1,T2,T3> {
|
template<> struct apply_on_zip3_impl<-1> {
|
||||||
template<typename F, typename ... Args>
|
template<typename F, typename T1, typename T2, typename T3,typename ... Args>
|
||||||
auto operator()(F && f, T1 const & t1, T2 const & t2, T3 const & t3, Args && ... args) DECL_AND_RETURN( std::make_tuple(std::forward<Args>(args)...));
|
auto operator()(F && f, T1 && t1, T2 && t2, T3 && t3, Args && ... args) DECL_AND_RETURN( std::make_tuple(std::forward<Args>(args)...));
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename F, typename T1, typename T2, typename T3>
|
template<typename F, typename T1, typename T2, typename T3>
|
||||||
auto apply_on_zip3 (F && f,T1 const & t1, T2 const & t2, T3 const & t3) DECL_AND_RETURN( apply_on_zip3_impl<std::tuple_size<T1>::value-1,T1,T2,T3>()(std::forward<F>(f),t1,t2,t3));
|
auto apply_on_zip3 (F && f,T1 && t1, T2 && t2, T3 && t3) DECL_AND_RETURN( apply_on_zip3_impl<std::tuple_size<typename std::remove_reference<T1>::type>::value-1>()(std::forward<F>(f),std::forward<T1>(t1),std::forward<T2>(t2),std::forward<T3>(t3)));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* fold(f, t1, init)
|
* fold(f, t1, init)
|
||||||
|
Loading…
Reference in New Issue
Block a user