From c1a012ad45c9c2f11eed6250ad1285e6ccaee0b8 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Tue, 16 May 2023 19:46:38 +0300 Subject: [PATCH] Add value list support to mp_take. Refs #53. --- include/boost/mp11/algorithm.hpp | 4 +- test/Jamfile | 1 + test/mp_take_2.cpp | 88 ++++++++++++++++++++++++++++++++ 3 files changed, 91 insertions(+), 2 deletions(-) create mode 100644 test/mp_take_2.cpp diff --git a/include/boost/mp11/algorithm.hpp b/include/boost/mp11/algorithm.hpp index 82a7aa9..7d7e579 100644 --- a/include/boost/mp11/algorithm.hpp +++ b/include/boost/mp11/algorithm.hpp @@ -470,8 +470,8 @@ struct mp_take_c_impl, typen } // namespace detail -template using mp_take_c = typename detail::mp_take_c_impl::type; -template using mp_take = typename detail::mp_take_c_impl::type; +template using mp_take_c = mp_assign>::type>; +template using mp_take = mp_take_c; // mp_back template using mp_back = mp_at_c::value - 1>; diff --git a/test/Jamfile b/test/Jamfile index 665354b..79c4eaf 100644 --- a/test/Jamfile +++ b/test/Jamfile @@ -97,6 +97,7 @@ run mp_at.cpp ; run mp_at_2.cpp ; run mp_at_sf.cpp : : : gcc-4.7:all ; run mp_take.cpp ; +run mp_take_2.cpp ; run mp_replace.cpp ; run mp_replace_if.cpp ; run mp_replace_if_q.cpp ; diff --git a/test/mp_take_2.cpp b/test/mp_take_2.cpp new file mode 100644 index 0000000..56adc5b --- /dev/null +++ b/test/mp_take_2.cpp @@ -0,0 +1,88 @@ +// Copyright 2023 Peter Dimov. +// Distributed under the Boost Software License, Version 1.0. +// https://www.boost.org/LICENSE_1_0.txt + +#include +#include +#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 + +template struct V1 {}; +template struct V2 {}; + +int main() +{ + using boost::mp11::mp_list; + using boost::mp11::mp_take; + using boost::mp11::mp_take_c; + using boost::mp11::mp_size_t; + + { + using L1 = V1<>; + + BOOST_TEST_TRAIT_SAME(mp_take_c, L1); + BOOST_TEST_TRAIT_SAME(mp_take>, L1); + + using L2 = V1; + + BOOST_TEST_TRAIT_SAME(mp_take_c, V1<>); + BOOST_TEST_TRAIT_SAME(mp_take_c, V1); + BOOST_TEST_TRAIT_SAME(mp_take_c, V1); + BOOST_TEST_TRAIT_SAME(mp_take_c, V1); + BOOST_TEST_TRAIT_SAME(mp_take_c, V1); + BOOST_TEST_TRAIT_SAME(mp_take_c, V1); + + BOOST_TEST_TRAIT_SAME(mp_take>, V1<>); + BOOST_TEST_TRAIT_SAME(mp_take>, V1); + BOOST_TEST_TRAIT_SAME(mp_take>, V1); + BOOST_TEST_TRAIT_SAME(mp_take>, V1); + BOOST_TEST_TRAIT_SAME(mp_take>, V1); + BOOST_TEST_TRAIT_SAME(mp_take>, V1); + } + + { + using L1 = V2<>; + + BOOST_TEST_TRAIT_SAME(mp_take_c, L1); + BOOST_TEST_TRAIT_SAME(mp_take>, L1); + + using L2 = V2<1, 2, 3, 4, 5>; + + BOOST_TEST_TRAIT_SAME(mp_take_c, V2<>); + BOOST_TEST_TRAIT_SAME(mp_take_c, V2<1>); + BOOST_TEST_TRAIT_SAME(mp_take_c, V2<1, 2>); + BOOST_TEST_TRAIT_SAME(mp_take_c, V2<1, 2, 3>); + BOOST_TEST_TRAIT_SAME(mp_take_c, V2<1, 2, 3, 4>); + BOOST_TEST_TRAIT_SAME(mp_take_c, V2<1, 2, 3, 4, 5>); + + BOOST_TEST_TRAIT_SAME(mp_take>, V2<>); + BOOST_TEST_TRAIT_SAME(mp_take>, V2<1>); + BOOST_TEST_TRAIT_SAME(mp_take>, V2<1, 2>); + BOOST_TEST_TRAIT_SAME(mp_take>, V2<1, 2, 3>); + BOOST_TEST_TRAIT_SAME(mp_take>, V2<1, 2, 3, 4>); + BOOST_TEST_TRAIT_SAME(mp_take>, V2<1, 2, 3, 4, 5>); + } + + using boost::mp11::mp_iota_c; + using boost::mp11::mp_rename_v; + + { + using L1 = mp_rename_v, V1>; + using L2 = mp_rename_v, V1>; + + BOOST_TEST_TRAIT_SAME(mp_take_c, L2); + BOOST_TEST_TRAIT_SAME(mp_take_c, L1); + } + + return boost::report_errors(); +} + +#endif