From c92d314009f477a7cb3ebd8dc9e320712ab7f3fd Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Sat, 1 Apr 2017 18:08:19 +0300 Subject: [PATCH] Implement mp_transform_if in terms of mp_transform --- include/boost/mp11/algorithm.hpp | 67 ++++++-------------------------- test/mp_transform_if.cpp | 10 +++++ 2 files changed, 22 insertions(+), 55 deletions(-) diff --git a/include/boost/mp11/algorithm.hpp b/include/boost/mp11/algorithm.hpp index f7d033d..503f5cd 100644 --- a/include/boost/mp11/algorithm.hpp +++ b/include/boost/mp11/algorithm.hpp @@ -105,65 +105,22 @@ template class F, template class L1, class... T1, t namespace detail { -/* template class P, template class F, class... L> struct mp_transform_if_impl { - // error: pack expansion used as argument for non-pack parameter of alias template - template using _f = mp_eval_if>, mp_first>, F, U...>; + // the stupid quote-unquote dance avoids "pack expansion used as argument for non-pack parameter of alias template" +#if defined( BOOST_MSVC ) && BOOST_WORKAROUND( BOOST_MSVC, <= 1910 ) + + template struct _f_ { using type = mp_eval_if, U...>>, mp_first>, mp_quote::template fn, U...>; }; + template using _f = typename _f_::type; + +#else + + template using _f = mp_eval_if, U...>>, mp_first>, mp_quote::template fn, U...>; + +#endif + using type = mp_transform<_f, L...>; }; -*/ - -template class P, template class F, class... L> struct mp_transform_if_impl; - -template class P, template class F, template class L, class... T> struct mp_transform_if_impl> -{ -#if defined( BOOST_MSVC ) && BOOST_WORKAROUND( BOOST_MSVC, <= 1910 ) - - template struct _f { using type = mp_eval_if>, U, F, U>; }; - using type = L::type...>; - -#else - - template using _f = mp_eval_if>, U, F, U>; - using type = L<_f...>; - -#endif -}; - -template class P, template class F, template class L1, class... T1, template class L2, class... T2> struct mp_transform_if_impl, L2> -{ - static_assert( sizeof...(T1) == sizeof...(T2), "The arguments of mp_transform_if should be of the same size" ); - -#if defined( BOOST_MSVC ) && BOOST_WORKAROUND( BOOST_MSVC, <= 1910 ) - - template struct _f { using type = mp_eval_if>, U1, F, U1, U2>; }; - using type = L1::type...>; - -#else - - template using _f = mp_eval_if>, U1, F, U1, U2>; - using type = L1<_f...>; - -#endif -}; - -template class P, template class F, template class L1, class... T1, template class L2, class... T2, template class L3, class... T3> struct mp_transform_if_impl, L2, L3> -{ - static_assert( sizeof...(T1) == sizeof...(T2) && sizeof...(T1) == sizeof...(T3), "The arguments of mp_transform_if should be of the same size" ); - -#if defined( BOOST_MSVC ) && BOOST_WORKAROUND( BOOST_MSVC, <= 1910 ) - - template struct _f { using type = mp_eval_if>, U1, F, U1, U2, U3>; }; - using type = L1::type...>; - -#else - - template using _f = mp_eval_if>, U1, F, U1, U2, U3>; - using type = L1<_f...>; - -#endif -}; } // namespace detail diff --git a/test/mp_transform_if.cpp b/test/mp_transform_if.cpp index 89292dd..048909a 100644 --- a/test/mp_transform_if.cpp +++ b/test/mp_transform_if.cpp @@ -26,6 +26,8 @@ template using add_pointer = T*; template using is_not_ref = mp_not>; template using second = T2; template using third = T3; +template using fourth = T4; +template using fifth = T5; int main() { @@ -58,6 +60,14 @@ int main() BOOST_TEST_TRAIT_TRUE((std::is_same>>, std::tuple, X2&, mp_size_t<2>, X4 const&>>)); BOOST_TEST_TRAIT_TRUE((std::is_same>>, std::pair, X2&>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same>>, mp_list, X2&, mp_size_t<2>, X4 const&>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same>>, std::tuple, X2&, mp_size_t<2>, X4 const&>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same>>, std::pair, X2&>>)); + + BOOST_TEST_TRAIT_TRUE((std::is_same>>, mp_list, X2&, mp_size_t<2>, X4 const&>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same>>, std::tuple, X2&, mp_size_t<2>, X4 const&>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same>>, std::pair, X2&>>)); + // return boost::report_errors();