forked from boostorg/mp11
Implement mp_transform_if in terms of mp_transform
This commit is contained in:
@ -105,65 +105,22 @@ template<template<class...> class F, template<class...> class L1, class... T1, t
|
||||
namespace detail
|
||||
{
|
||||
|
||||
/*
|
||||
template<template<class...> class P, template<class...> class F, class... L> struct mp_transform_if_impl
|
||||
{
|
||||
// error: pack expansion used as argument for non-pack parameter of alias template
|
||||
template<class... U> using _f = mp_eval_if<mp_not<P<U...>>, mp_first<mp_list<U...>>, 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<class... U> struct _f_ { using type = mp_eval_if<mp_not<mp_invoke<mp_quote<P>, U...>>, mp_first<mp_list<U...>>, mp_quote<F>::template fn, U...>; };
|
||||
template<class... U> using _f = typename _f_<U...>::type;
|
||||
|
||||
#else
|
||||
|
||||
template<class... U> using _f = mp_eval_if<mp_not<mp_invoke<mp_quote<P>, U...>>, mp_first<mp_list<U...>>, mp_quote<F>::template fn, U...>;
|
||||
|
||||
#endif
|
||||
|
||||
using type = mp_transform<_f, L...>;
|
||||
};
|
||||
*/
|
||||
|
||||
template<template<class...> class P, template<class...> class F, class... L> struct mp_transform_if_impl;
|
||||
|
||||
template<template<class...> class P, template<class...> class F, template<class...> class L, class... T> struct mp_transform_if_impl<P, F, L<T...>>
|
||||
{
|
||||
#if defined( BOOST_MSVC ) && BOOST_WORKAROUND( BOOST_MSVC, <= 1910 )
|
||||
|
||||
template<class U> struct _f { using type = mp_eval_if<mp_not<P<U>>, U, F, U>; };
|
||||
using type = L<typename _f<T>::type...>;
|
||||
|
||||
#else
|
||||
|
||||
template<class U> using _f = mp_eval_if<mp_not<P<U>>, U, F, U>;
|
||||
using type = L<_f<T>...>;
|
||||
|
||||
#endif
|
||||
};
|
||||
|
||||
template<template<class...> class P, template<class...> class F, template<class...> class L1, class... T1, template<class...> class L2, class... T2> struct mp_transform_if_impl<P, F, L1<T1...>, L2<T2...>>
|
||||
{
|
||||
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<class U1, class U2> struct _f { using type = mp_eval_if<mp_not<P<U1, U2>>, U1, F, U1, U2>; };
|
||||
using type = L1<typename _f<T1, T2>::type...>;
|
||||
|
||||
#else
|
||||
|
||||
template<class U1, class U2> using _f = mp_eval_if<mp_not<P<U1, U2>>, U1, F, U1, U2>;
|
||||
using type = L1<_f<T1, T2>...>;
|
||||
|
||||
#endif
|
||||
};
|
||||
|
||||
template<template<class...> class P, template<class...> class F, template<class...> class L1, class... T1, template<class...> class L2, class... T2, template<class...> class L3, class... T3> struct mp_transform_if_impl<P, F, L1<T1...>, L2<T2...>, L3<T3...>>
|
||||
{
|
||||
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<class U1, class U2, class U3> struct _f { using type = mp_eval_if<mp_not<P<U1, U2, U3>>, U1, F, U1, U2, U3>; };
|
||||
using type = L1<typename _f<T1, T2, T3>::type...>;
|
||||
|
||||
#else
|
||||
|
||||
template<class U1, class U2, class U3> using _f = mp_eval_if<mp_not<P<U1, U2, U3>>, U1, F, U1, U2, U3>;
|
||||
using type = L1<_f<T1, T2, T3>...>;
|
||||
|
||||
#endif
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
|
@ -26,6 +26,8 @@ template<class T> using add_pointer = T*;
|
||||
template<class T, class...> using is_not_ref = mp_not<std::is_reference<T>>;
|
||||
template<class T1, class T2> using second = T2;
|
||||
template<class T1, class T2, class T3> using third = T3;
|
||||
template<class T1, class T2, class T3, class T4> using fourth = T4;
|
||||
template<class T1, class T2, class T3, class T4, class T5> using fifth = T5;
|
||||
|
||||
int main()
|
||||
{
|
||||
@ -58,6 +60,14 @@ int main()
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_transform_if<is_not_ref, third, L2, L2, mp_iota<mp_size<L2>>>, std::tuple<mp_size_t<0>, X2&, mp_size_t<2>, X4 const&>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_transform_if<is_not_ref, third, L3, L3, mp_iota<mp_size<L3>>>, std::pair<mp_size_t<0>, X2&>>));
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_transform_if<is_not_ref, fourth, L1, L1, L1, mp_iota<mp_size<L1>>>, mp_list<mp_size_t<0>, X2&, mp_size_t<2>, X4 const&>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_transform_if<is_not_ref, fourth, L2, L2, L2, mp_iota<mp_size<L2>>>, std::tuple<mp_size_t<0>, X2&, mp_size_t<2>, X4 const&>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_transform_if<is_not_ref, fourth, L3, L3, L3, mp_iota<mp_size<L3>>>, std::pair<mp_size_t<0>, X2&>>));
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_transform_if<is_not_ref, fifth, L1, L1, L1, L1, mp_iota<mp_size<L1>>>, mp_list<mp_size_t<0>, X2&, mp_size_t<2>, X4 const&>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_transform_if<is_not_ref, fifth, L2, L2, L2, L2, mp_iota<mp_size<L2>>>, std::tuple<mp_size_t<0>, X2&, mp_size_t<2>, X4 const&>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_transform_if<is_not_ref, fifth, L3, L3, L3, L3, mp_iota<mp_size<L3>>>, std::pair<mp_size_t<0>, X2&>>));
|
||||
|
||||
//
|
||||
|
||||
return boost::report_errors();
|
||||
|
Reference in New Issue
Block a user