1
0
forked from boostorg/mp11

Add support for value lists to mp_transform_first, mp_transform_second, mp_transform_third. Refs #53.

This commit is contained in:
Peter Dimov
2023-05-15 20:11:34 +03:00
parent 4545835a8b
commit 0113ee9246
5 changed files with 251 additions and 0 deletions

View File

@@ -386,6 +386,15 @@ template<template<class...> class L, class U1, class... U, template<class...> cl
using type = L<F<U1>, U...>;
};
#if defined(BOOST_MP11_HAS_TEMPLATE_AUTO)
template<template<auto...> class L, auto A1, auto... A, template<class...> class F> struct mp_transform_front_impl<L<A1, A...>, F>
{
using type = L<F<mp_value<A1>>::value, A...>;
};
#endif
} // namespace detail
template<class L, template<class...> class F> using mp_transform_front = typename detail::mp_transform_front_impl<L, F>::type;
@@ -410,6 +419,15 @@ template<template<class...> class L, class U1, class U2, class... U, template<cl
using type = L<U1, F<U2>, U...>;
};
#if defined(BOOST_MP11_HAS_TEMPLATE_AUTO)
template<template<auto...> class L, auto A1, auto A2, auto... A, template<class...> class F> struct mp_transform_second_impl<L<A1, A2, A...>, F>
{
using type = L<A1, F<mp_value<A2>>::value, A...>;
};
#endif
} // namespace detail
template<class L, template<class...> class F> using mp_transform_second = typename detail::mp_transform_second_impl<L, F>::type;
@@ -430,6 +448,15 @@ template<template<class...> class L, class U1, class U2, class U3, class... U, t
using type = L<U1, U2, F<U3>, U...>;
};
#if defined(BOOST_MP11_HAS_TEMPLATE_AUTO)
template<template<auto...> class L, auto A1, auto A2, auto A3, auto... A, template<class...> class F> struct mp_transform_third_impl<L<A1, A2, A3, A...>, F>
{
using type = L<A1, A2, F<mp_value<A3>>::value, A...>;
};
#endif
} // namespace detail
template<class L, template<class...> class F> using mp_transform_third = typename detail::mp_transform_third_impl<L, F>::type;

View File

@@ -61,8 +61,11 @@ run mp_apply_q_sf.cpp ;
run mp_is_list.cpp ;
run mp_list_c.cpp ;
run mp_transform_front.cpp ;
run mp_transform_front_2.cpp ;
run mp_transform_second.cpp ;
run mp_transform_second_2.cpp ;
run mp_transform_third.cpp ;
run mp_transform_third_2.cpp ;
run mp_list_v.cpp ;
run mp_rename_v.cpp ;

View File

@@ -0,0 +1,99 @@
// Copyright 2023 Peter Dimov
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#include <boost/mp11/list.hpp>
#if !defined(BOOST_MP11_HAS_TEMPLATE_AUTO)
#pragma message("Test skipped because BOOST_MP11_HAS_TEMPLATE_AUTO is not defined")
int main() {}
#else
#include <boost/mp11/integral.hpp>
#include <boost/mp11/utility.hpp>
#include <boost/core/lightweight_test_trait.hpp>
template<auto... A> struct L1 {};
template<int... I> struct L2 {};
template<class N> using double_ = boost::mp11::mp_value< N::value * 2 >;
using Q_double = boost::mp11::mp_quote<double_>;
template<class N> using is_zero = boost::mp11::mp_bool< N::value == 0 >;
using Q_is_zero = boost::mp11::mp_quote<is_zero>;
int main()
{
using boost::mp11::mp_transform_front;
using boost::mp11::mp_transform_first;
using boost::mp11::mp_transform_front_q;
using boost::mp11::mp_transform_first_q;
//
BOOST_TEST_TRAIT_SAME(mp_transform_front<L1<3>, double_>, L1<6>);
BOOST_TEST_TRAIT_SAME(mp_transform_first<L1<3>, double_>, L1<6>);
BOOST_TEST_TRAIT_SAME(mp_transform_front_q<L1<3>, Q_double>, L1<6>);
BOOST_TEST_TRAIT_SAME(mp_transform_first_q<L1<3>, Q_double>, L1<6>);
BOOST_TEST_TRAIT_SAME(mp_transform_front<L1<3, false>, double_>, L1<6, false>);
BOOST_TEST_TRAIT_SAME(mp_transform_first<L1<3, false>, double_>, L1<6, false>);
BOOST_TEST_TRAIT_SAME(mp_transform_front_q<L1<3, false>, Q_double>, L1<6, false>);
BOOST_TEST_TRAIT_SAME(mp_transform_first_q<L1<3, false>, Q_double>, L1<6, false>);
BOOST_TEST_TRAIT_SAME(mp_transform_front<L1<3, false, true>, double_>, L1<6, false, true>);
BOOST_TEST_TRAIT_SAME(mp_transform_first<L1<3, false, true>, double_>, L1<6, false, true>);
BOOST_TEST_TRAIT_SAME(mp_transform_front_q<L1<3, false, true>, Q_double>, L1<6, false, true>);
BOOST_TEST_TRAIT_SAME(mp_transform_first_q<L1<3, false, true>, Q_double>, L1<6, false, true>);
//
BOOST_TEST_TRAIT_SAME(mp_transform_front<L1<0>, is_zero>, L1<true>);
BOOST_TEST_TRAIT_SAME(mp_transform_first<L1<0>, is_zero>, L1<true>);
BOOST_TEST_TRAIT_SAME(mp_transform_front_q<L1<0>, Q_is_zero>, L1<true>);
BOOST_TEST_TRAIT_SAME(mp_transform_first_q<L1<0>, Q_is_zero>, L1<true>);
BOOST_TEST_TRAIT_SAME(mp_transform_front<L1<0, 1>, is_zero>, L1<true, 1>);
BOOST_TEST_TRAIT_SAME(mp_transform_first<L1<0, 1>, is_zero>, L1<true, 1>);
BOOST_TEST_TRAIT_SAME(mp_transform_front_q<L1<0, 1>, Q_is_zero>, L1<true, 1>);
BOOST_TEST_TRAIT_SAME(mp_transform_first_q<L1<0, 1>, Q_is_zero>, L1<true, 1>);
BOOST_TEST_TRAIT_SAME(mp_transform_front<L1<0, 1, 2>, is_zero>, L1<true, 1, 2>);
BOOST_TEST_TRAIT_SAME(mp_transform_first<L1<0, 1, 2>, is_zero>, L1<true, 1, 2>);
BOOST_TEST_TRAIT_SAME(mp_transform_front_q<L1<0, 1, 2>, Q_is_zero>, L1<true, 1, 2>);
BOOST_TEST_TRAIT_SAME(mp_transform_first_q<L1<0, 1, 2>, Q_is_zero>, L1<true, 1, 2>);
//
BOOST_TEST_TRAIT_SAME(mp_transform_front<L2<3>, double_>, L2<6>);
BOOST_TEST_TRAIT_SAME(mp_transform_first<L2<3>, double_>, L2<6>);
BOOST_TEST_TRAIT_SAME(mp_transform_front_q<L2<3>, Q_double>, L2<6>);
BOOST_TEST_TRAIT_SAME(mp_transform_first_q<L2<3>, Q_double>, L2<6>);
BOOST_TEST_TRAIT_SAME(mp_transform_front<L2<3, 2>, double_>, L2<6, 2>);
BOOST_TEST_TRAIT_SAME(mp_transform_first<L2<3, 2>, double_>, L2<6, 2>);
BOOST_TEST_TRAIT_SAME(mp_transform_front_q<L2<3, 2>, Q_double>, L2<6, 2>);
BOOST_TEST_TRAIT_SAME(mp_transform_first_q<L2<3, 2>, Q_double>, L2<6, 2>);
BOOST_TEST_TRAIT_SAME(mp_transform_front<L2<3, 2, 1>, double_>, L2<6, 2, 1>);
BOOST_TEST_TRAIT_SAME(mp_transform_first<L2<3, 2, 1>, double_>, L2<6, 2, 1>);
BOOST_TEST_TRAIT_SAME(mp_transform_front_q<L2<3, 2, 1>, Q_double>, L2<6, 2, 1>);
BOOST_TEST_TRAIT_SAME(mp_transform_first_q<L2<3, 2, 1>, Q_double>, L2<6, 2, 1>);
//
return boost::report_errors();
}
#endif

View File

@@ -0,0 +1,61 @@
// Copyright 2023 Peter Dimov
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#include <boost/mp11/list.hpp>
#if !defined(BOOST_MP11_HAS_TEMPLATE_AUTO)
#pragma message("Test skipped because BOOST_MP11_HAS_TEMPLATE_AUTO is not defined")
int main() {}
#else
#include <boost/mp11/integral.hpp>
#include <boost/mp11/utility.hpp>
#include <boost/core/lightweight_test_trait.hpp>
template<auto... A> struct L1 {};
template<int... I> struct L2 {};
template<class N> using double_ = boost::mp11::mp_value< N::value * 2 >;
using Q_double = boost::mp11::mp_quote<double_>;
template<class N> using is_zero = boost::mp11::mp_bool< N::value == 0 >;
using Q_is_zero = boost::mp11::mp_quote<is_zero>;
int main()
{
using boost::mp11::mp_transform_second;
using boost::mp11::mp_transform_second_q;
//
BOOST_TEST_TRAIT_SAME(mp_transform_second<L1<false, 3>, double_>, L1<false, 6>);
BOOST_TEST_TRAIT_SAME(mp_transform_second_q<L1<false, 3>, Q_double>, L1<false, 6>);
BOOST_TEST_TRAIT_SAME(mp_transform_second<L1<false, 3, true>, double_>, L1<false, 6, true>);
BOOST_TEST_TRAIT_SAME(mp_transform_second_q<L1<false, 3, true>, Q_double>, L1<false, 6, true>);
//
BOOST_TEST_TRAIT_SAME(mp_transform_second<L1<0, 1>, is_zero>, L1<0, false>);
BOOST_TEST_TRAIT_SAME(mp_transform_second_q<L1<0, 1>, Q_is_zero>, L1<0, false>);
BOOST_TEST_TRAIT_SAME(mp_transform_second<L1<0, 1, 2>, is_zero>, L1<0, false, 2>);
BOOST_TEST_TRAIT_SAME(mp_transform_second_q<L1<0, 1, 2>, Q_is_zero>, L1<0, false, 2>);
//
BOOST_TEST_TRAIT_SAME(mp_transform_second<L2<3, 2>, double_>, L2<3, 4>);
BOOST_TEST_TRAIT_SAME(mp_transform_second_q<L2<3, 2>, Q_double>, L2<3, 4>);
BOOST_TEST_TRAIT_SAME(mp_transform_second<L2<3, 2, 1>, double_>, L2<3, 4, 1>);
BOOST_TEST_TRAIT_SAME(mp_transform_second_q<L2<3, 2, 1>, Q_double>, L2<3, 4, 1>);
//
return boost::report_errors();
}
#endif

View File

@@ -0,0 +1,61 @@
// Copyright 2023 Peter Dimov
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#include <boost/mp11/list.hpp>
#if !defined(BOOST_MP11_HAS_TEMPLATE_AUTO)
#pragma message("Test skipped because BOOST_MP11_HAS_TEMPLATE_AUTO is not defined")
int main() {}
#else
#include <boost/mp11/integral.hpp>
#include <boost/mp11/utility.hpp>
#include <boost/core/lightweight_test_trait.hpp>
template<auto... A> struct L1 {};
template<int... I> struct L2 {};
template<class N> using double_ = boost::mp11::mp_value< N::value * 2 >;
using Q_double = boost::mp11::mp_quote<double_>;
template<class N> using is_zero = boost::mp11::mp_bool< N::value == 0 >;
using Q_is_zero = boost::mp11::mp_quote<is_zero>;
int main()
{
using boost::mp11::mp_transform_third;
using boost::mp11::mp_transform_third_q;
//
BOOST_TEST_TRAIT_SAME(mp_transform_third<L1<false, true, 3>, double_>, L1<false, true, 6>);
BOOST_TEST_TRAIT_SAME(mp_transform_third_q<L1<false, true, 3>, Q_double>, L1<false, true, 6>);
BOOST_TEST_TRAIT_SAME(mp_transform_third<L1<false, true, 3, 4>, double_>, L1<false, true, 6, 4>);
BOOST_TEST_TRAIT_SAME(mp_transform_third_q<L1<false, true, 3, 4>, Q_double>, L1<false, true, 6, 4>);
//
BOOST_TEST_TRAIT_SAME(mp_transform_third<L1<0, 1, 2>, is_zero>, L1<0, 1, false>);
BOOST_TEST_TRAIT_SAME(mp_transform_third_q<L1<0, 1, 2>, Q_is_zero>, L1<0, 1, false>);
BOOST_TEST_TRAIT_SAME(mp_transform_third<L1<0, 1, 2, 3>, is_zero>, L1<0, 1, false, 3>);
BOOST_TEST_TRAIT_SAME(mp_transform_third_q<L1<0, 1, 2, 3>, Q_is_zero>, L1<0, 1, false, 3>);
//
BOOST_TEST_TRAIT_SAME(mp_transform_third<L2<3, 2, 1>, double_>, L2<3, 2, 2>);
BOOST_TEST_TRAIT_SAME(mp_transform_third_q<L2<3, 2, 1>, Q_double>, L2<3, 2, 2>);
BOOST_TEST_TRAIT_SAME(mp_transform_third<L2<3, 2, 1, 0>, double_>, L2<3, 2, 2, 0>);
BOOST_TEST_TRAIT_SAME(mp_transform_third_q<L2<3, 2, 1, 0>, Q_double>, L2<3, 2, 2, 0>);
//
return boost::report_errors();
}
#endif