From 0113ee9246e1daad1b0fba53fa068edc06c6eb85 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Mon, 15 May 2023 20:11:34 +0300 Subject: [PATCH] Add support for value lists to mp_transform_first, mp_transform_second, mp_transform_third. Refs #53. --- include/boost/mp11/list.hpp | 27 ++++++++++ test/Jamfile | 3 ++ test/mp_transform_front_2.cpp | 99 ++++++++++++++++++++++++++++++++++ test/mp_transform_second_2.cpp | 61 +++++++++++++++++++++ test/mp_transform_third_2.cpp | 61 +++++++++++++++++++++ 5 files changed, 251 insertions(+) create mode 100644 test/mp_transform_front_2.cpp create mode 100644 test/mp_transform_second_2.cpp create mode 100644 test/mp_transform_third_2.cpp diff --git a/include/boost/mp11/list.hpp b/include/boost/mp11/list.hpp index 586e10c..397252f 100644 --- a/include/boost/mp11/list.hpp +++ b/include/boost/mp11/list.hpp @@ -386,6 +386,15 @@ template class L, class U1, class... U, template cl using type = L, U...>; }; +#if defined(BOOST_MP11_HAS_TEMPLATE_AUTO) + +template class L, auto A1, auto... A, template class F> struct mp_transform_front_impl, F> +{ + using type = L>::value, A...>; +}; + +#endif + } // namespace detail template class F> using mp_transform_front = typename detail::mp_transform_front_impl::type; @@ -410,6 +419,15 @@ template class L, class U1, class U2, class... U, template, U...>; }; +#if defined(BOOST_MP11_HAS_TEMPLATE_AUTO) + +template class L, auto A1, auto A2, auto... A, template class F> struct mp_transform_second_impl, F> +{ + using type = L>::value, A...>; +}; + +#endif + } // namespace detail template class F> using mp_transform_second = typename detail::mp_transform_second_impl::type; @@ -430,6 +448,15 @@ template class L, class U1, class U2, class U3, class... U, t using type = L, U...>; }; +#if defined(BOOST_MP11_HAS_TEMPLATE_AUTO) + +template class L, auto A1, auto A2, auto A3, auto... A, template class F> struct mp_transform_third_impl, F> +{ + using type = L>::value, A...>; +}; + +#endif + } // namespace detail template class F> using mp_transform_third = typename detail::mp_transform_third_impl::type; diff --git a/test/Jamfile b/test/Jamfile index 269f535..62bb206 100644 --- a/test/Jamfile +++ b/test/Jamfile @@ -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 ; diff --git a/test/mp_transform_front_2.cpp b/test/mp_transform_front_2.cpp new file mode 100644 index 0000000..6c8b207 --- /dev/null +++ b/test/mp_transform_front_2.cpp @@ -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 + +#if !defined(BOOST_MP11_HAS_TEMPLATE_AUTO) + +#pragma message("Test skipped because BOOST_MP11_HAS_TEMPLATE_AUTO is not defined") +int main() {} + +#else + +#include +#include +#include + +template struct L1 {}; +template struct L2 {}; + +template using double_ = boost::mp11::mp_value< N::value * 2 >; +using Q_double = boost::mp11::mp_quote; + +template using is_zero = boost::mp11::mp_bool< N::value == 0 >; +using Q_is_zero = boost::mp11::mp_quote; + +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, double_>, L1<6>); + BOOST_TEST_TRAIT_SAME(mp_transform_first, double_>, L1<6>); + + BOOST_TEST_TRAIT_SAME(mp_transform_front_q, Q_double>, L1<6>); + BOOST_TEST_TRAIT_SAME(mp_transform_first_q, Q_double>, L1<6>); + + BOOST_TEST_TRAIT_SAME(mp_transform_front, double_>, L1<6, false>); + BOOST_TEST_TRAIT_SAME(mp_transform_first, double_>, L1<6, false>); + + BOOST_TEST_TRAIT_SAME(mp_transform_front_q, Q_double>, L1<6, false>); + BOOST_TEST_TRAIT_SAME(mp_transform_first_q, Q_double>, L1<6, false>); + + BOOST_TEST_TRAIT_SAME(mp_transform_front, double_>, L1<6, false, true>); + BOOST_TEST_TRAIT_SAME(mp_transform_first, double_>, L1<6, false, true>); + + BOOST_TEST_TRAIT_SAME(mp_transform_front_q, Q_double>, L1<6, false, true>); + BOOST_TEST_TRAIT_SAME(mp_transform_first_q, Q_double>, L1<6, false, true>); + + // + + BOOST_TEST_TRAIT_SAME(mp_transform_front, is_zero>, L1); + BOOST_TEST_TRAIT_SAME(mp_transform_first, is_zero>, L1); + + BOOST_TEST_TRAIT_SAME(mp_transform_front_q, Q_is_zero>, L1); + BOOST_TEST_TRAIT_SAME(mp_transform_first_q, Q_is_zero>, L1); + + BOOST_TEST_TRAIT_SAME(mp_transform_front, is_zero>, L1); + BOOST_TEST_TRAIT_SAME(mp_transform_first, is_zero>, L1); + + BOOST_TEST_TRAIT_SAME(mp_transform_front_q, Q_is_zero>, L1); + BOOST_TEST_TRAIT_SAME(mp_transform_first_q, Q_is_zero>, L1); + + BOOST_TEST_TRAIT_SAME(mp_transform_front, is_zero>, L1); + BOOST_TEST_TRAIT_SAME(mp_transform_first, is_zero>, L1); + + BOOST_TEST_TRAIT_SAME(mp_transform_front_q, Q_is_zero>, L1); + BOOST_TEST_TRAIT_SAME(mp_transform_first_q, Q_is_zero>, L1); + + // + + BOOST_TEST_TRAIT_SAME(mp_transform_front, double_>, L2<6>); + BOOST_TEST_TRAIT_SAME(mp_transform_first, double_>, L2<6>); + + BOOST_TEST_TRAIT_SAME(mp_transform_front_q, Q_double>, L2<6>); + BOOST_TEST_TRAIT_SAME(mp_transform_first_q, Q_double>, L2<6>); + + BOOST_TEST_TRAIT_SAME(mp_transform_front, double_>, L2<6, 2>); + BOOST_TEST_TRAIT_SAME(mp_transform_first, double_>, L2<6, 2>); + + BOOST_TEST_TRAIT_SAME(mp_transform_front_q, Q_double>, L2<6, 2>); + BOOST_TEST_TRAIT_SAME(mp_transform_first_q, Q_double>, L2<6, 2>); + + BOOST_TEST_TRAIT_SAME(mp_transform_front, double_>, L2<6, 2, 1>); + BOOST_TEST_TRAIT_SAME(mp_transform_first, double_>, L2<6, 2, 1>); + + BOOST_TEST_TRAIT_SAME(mp_transform_front_q, Q_double>, L2<6, 2, 1>); + BOOST_TEST_TRAIT_SAME(mp_transform_first_q, Q_double>, L2<6, 2, 1>); + + // + + return boost::report_errors(); +} + +#endif diff --git a/test/mp_transform_second_2.cpp b/test/mp_transform_second_2.cpp new file mode 100644 index 0000000..ebc2408 --- /dev/null +++ b/test/mp_transform_second_2.cpp @@ -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 + +#if !defined(BOOST_MP11_HAS_TEMPLATE_AUTO) + +#pragma message("Test skipped because BOOST_MP11_HAS_TEMPLATE_AUTO is not defined") +int main() {} + +#else + +#include +#include +#include + +template struct L1 {}; +template struct L2 {}; + +template using double_ = boost::mp11::mp_value< N::value * 2 >; +using Q_double = boost::mp11::mp_quote; + +template using is_zero = boost::mp11::mp_bool< N::value == 0 >; +using Q_is_zero = boost::mp11::mp_quote; + +int main() +{ + using boost::mp11::mp_transform_second; + using boost::mp11::mp_transform_second_q; + + // + + BOOST_TEST_TRAIT_SAME(mp_transform_second, double_>, L1); + BOOST_TEST_TRAIT_SAME(mp_transform_second_q, Q_double>, L1); + + BOOST_TEST_TRAIT_SAME(mp_transform_second, double_>, L1); + BOOST_TEST_TRAIT_SAME(mp_transform_second_q, Q_double>, L1); + + // + + BOOST_TEST_TRAIT_SAME(mp_transform_second, is_zero>, L1<0, false>); + BOOST_TEST_TRAIT_SAME(mp_transform_second_q, Q_is_zero>, L1<0, false>); + + BOOST_TEST_TRAIT_SAME(mp_transform_second, is_zero>, L1<0, false, 2>); + BOOST_TEST_TRAIT_SAME(mp_transform_second_q, Q_is_zero>, L1<0, false, 2>); + + // + + BOOST_TEST_TRAIT_SAME(mp_transform_second, double_>, L2<3, 4>); + BOOST_TEST_TRAIT_SAME(mp_transform_second_q, Q_double>, L2<3, 4>); + + BOOST_TEST_TRAIT_SAME(mp_transform_second, double_>, L2<3, 4, 1>); + BOOST_TEST_TRAIT_SAME(mp_transform_second_q, Q_double>, L2<3, 4, 1>); + + // + + return boost::report_errors(); +} + +#endif diff --git a/test/mp_transform_third_2.cpp b/test/mp_transform_third_2.cpp new file mode 100644 index 0000000..ac35e64 --- /dev/null +++ b/test/mp_transform_third_2.cpp @@ -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 + +#if !defined(BOOST_MP11_HAS_TEMPLATE_AUTO) + +#pragma message("Test skipped because BOOST_MP11_HAS_TEMPLATE_AUTO is not defined") +int main() {} + +#else + +#include +#include +#include + +template struct L1 {}; +template struct L2 {}; + +template using double_ = boost::mp11::mp_value< N::value * 2 >; +using Q_double = boost::mp11::mp_quote; + +template using is_zero = boost::mp11::mp_bool< N::value == 0 >; +using Q_is_zero = boost::mp11::mp_quote; + +int main() +{ + using boost::mp11::mp_transform_third; + using boost::mp11::mp_transform_third_q; + + // + + BOOST_TEST_TRAIT_SAME(mp_transform_third, double_>, L1); + BOOST_TEST_TRAIT_SAME(mp_transform_third_q, Q_double>, L1); + + BOOST_TEST_TRAIT_SAME(mp_transform_third, double_>, L1); + BOOST_TEST_TRAIT_SAME(mp_transform_third_q, Q_double>, L1); + + // + + BOOST_TEST_TRAIT_SAME(mp_transform_third, is_zero>, L1<0, 1, false>); + BOOST_TEST_TRAIT_SAME(mp_transform_third_q, Q_is_zero>, L1<0, 1, false>); + + BOOST_TEST_TRAIT_SAME(mp_transform_third, is_zero>, L1<0, 1, false, 3>); + BOOST_TEST_TRAIT_SAME(mp_transform_third_q, Q_is_zero>, L1<0, 1, false, 3>); + + // + + BOOST_TEST_TRAIT_SAME(mp_transform_third, double_>, L2<3, 2, 2>); + BOOST_TEST_TRAIT_SAME(mp_transform_third_q, Q_double>, L2<3, 2, 2>); + + BOOST_TEST_TRAIT_SAME(mp_transform_third, double_>, L2<3, 2, 2, 0>); + BOOST_TEST_TRAIT_SAME(mp_transform_third_q, Q_double>, L2<3, 2, 2, 0>); + + // + + return boost::report_errors(); +} + +#endif