From fcbe835f4bfa4bdb791769ab276880f20cd8a55d Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Sat, 1 Apr 2017 17:39:02 +0300 Subject: [PATCH] Add a variadic mp_transform implementation --- include/boost/mp11/algorithm.hpp | 32 ++++++++++++++++++++++++++++++-- test/mp_transform.cpp | 20 ++++++++++++++++++++ 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/include/boost/mp11/algorithm.hpp b/include/boost/mp11/algorithm.hpp index cda0eb7..f7d033d 100644 --- a/include/boost/mp11/algorithm.hpp +++ b/include/boost/mp11/algorithm.hpp @@ -44,6 +44,16 @@ template using mp_assign = typename detail::mp_assign_impl template using mp_clear = mp_assign>; +// mp_fold forward declaration +namespace detail +{ + +template class F> struct mp_fold_impl; + +} // namespace detail + +template class F> using mp_fold = typename detail::mp_fold_impl::type; + // mp_transform namespace detail { @@ -71,6 +81,26 @@ template class F, template class L1, class... T1, t template class F, class... L> using mp_transform = typename detail::mp_transform_impl::type; +namespace detail +{ + +template class F, template class L1, class... T1, template class L2, class... T2, template class L3, class... T3, template class L4, class... T4, class... L> struct mp_transform_impl, L2, L3, L4, L...> +{ + static_assert( sizeof...(T1) == sizeof...(T2) && sizeof...(T1) == sizeof...(T3) && sizeof...(T1) == sizeof...(T4), "The arguments of mp_transform should be of the same size" ); + + using A1 = L1...>; + + template using _f = mp_transform; + + using A2 = mp_fold, A1, _f>; + + template using _g = mp_apply; + + using type = mp_transform<_g, A2>; +}; + +} // namespace detail + // mp_transform_if namespace detail { @@ -753,8 +783,6 @@ template class L, class T1, class T2, class T3, class T4, cla } // namespace detail -template class F> using mp_fold = typename detail::mp_fold_impl::type; - // mp_reverse_fold namespace detail { diff --git a/test/mp_transform.cpp b/test/mp_transform.cpp index 6782278..ed6f1dd 100644 --- a/test/mp_transform.cpp +++ b/test/mp_transform.cpp @@ -29,6 +29,15 @@ struct Z2 {}; struct Z3 {}; struct Z4 {}; +struct U1 {}; +struct U2 {}; + +struct V1 {}; +struct V2 {}; + +struct W1 {}; +struct W2 {}; + template using add_pointer = typename std::add_pointer::type; template using is_same = typename std::is_same::type; @@ -81,5 +90,16 @@ int main() // + using L8 = std::pair; + using L9 = std::pair; + using L10 = std::pair; + using L11 = std::pair; + + BOOST_TEST_TRAIT_TRUE((std::is_same, std::pair, std::tuple>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, std::pair, std::tuple>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, std::pair, std::tuple>>)); + + // + return boost::report_errors(); }