From 73626ba3bc992f11acfb5c9c887128f66e5b2013 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Tue, 16 May 2023 19:13:56 +0300 Subject: [PATCH] Add value list support to mp_at. Refs #53. --- include/boost/mp11/algorithm.hpp | 11 +++++- test/Jamfile | 1 + test/mp_at_2.cpp | 64 ++++++++++++++++++++++++++++++++ 3 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 test/mp_at_2.cpp diff --git a/include/boost/mp11/algorithm.hpp b/include/boost/mp11/algorithm.hpp index e73e7fe..82a7aa9 100644 --- a/include/boost/mp11/algorithm.hpp +++ b/include/boost/mp11/algorithm.hpp @@ -352,11 +352,20 @@ template class L, class... T, std::size_t I> struct mp_at_c_i using type = __type_pack_element; }; +#if defined(BOOST_MP11_HAS_TEMPLATE_AUTO) + +template class L, auto... A, std::size_t I> struct mp_at_c_impl, I> +{ + using type = __type_pack_element...>; +}; + +#endif + #else template struct mp_at_c_impl { - using _map = mp_transform >, L>; + using _map = mp_transform >, mp_rename>; using type = mp_second > >; }; diff --git a/test/Jamfile b/test/Jamfile index 009cf72..886a31c 100644 --- a/test/Jamfile +++ b/test/Jamfile @@ -94,6 +94,7 @@ run mp_drop.cpp ; run mp_iota.cpp ; run mp_iota_2.cpp ; run mp_at.cpp ; +run mp_at_2.cpp ; run mp_at_sf.cpp : : : gcc-4.7:all ; run mp_take.cpp ; run mp_replace.cpp ; diff --git a/test/mp_at_2.cpp b/test/mp_at_2.cpp new file mode 100644 index 0000000..c111d3a --- /dev/null +++ b/test/mp_at_2.cpp @@ -0,0 +1,64 @@ +// Copyright 2023 Peter Dimov +// Distributed under the Boost Software License, Version 1.0. +// https://www.boost.org/LICENSE_1_0.txt + +#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_at; + using boost::mp11::mp_at_c; + using boost::mp11::mp_false; + using boost::mp11::mp_true; + using boost::mp11::mp_int; + using boost::mp11::mp_size_t; + + { + using L1 = V1; + + BOOST_TEST_TRAIT_SAME(mp_at_c, mp_false); + BOOST_TEST_TRAIT_SAME(mp_at_c, mp_int<0>); + BOOST_TEST_TRAIT_SAME(mp_at_c, mp_true); + BOOST_TEST_TRAIT_SAME(mp_at_c, mp_int<1>); + BOOST_TEST_TRAIT_SAME(mp_at_c, mp_size_t<2>); + + BOOST_TEST_TRAIT_SAME(mp_at>, mp_false); + BOOST_TEST_TRAIT_SAME(mp_at>, mp_int<0>); + BOOST_TEST_TRAIT_SAME(mp_at>, mp_true); + BOOST_TEST_TRAIT_SAME(mp_at>, mp_int<1>); + BOOST_TEST_TRAIT_SAME(mp_at>, mp_size_t<2>); + } + + { + using L1 = V2<1, 2, 3, 4, 5>; + + BOOST_TEST_TRAIT_SAME(mp_at_c, mp_int<1>); + BOOST_TEST_TRAIT_SAME(mp_at_c, mp_int<2>); + BOOST_TEST_TRAIT_SAME(mp_at_c, mp_int<3>); + BOOST_TEST_TRAIT_SAME(mp_at_c, mp_int<4>); + BOOST_TEST_TRAIT_SAME(mp_at_c, mp_int<5>); + + BOOST_TEST_TRAIT_SAME(mp_at>, mp_int<1>); + BOOST_TEST_TRAIT_SAME(mp_at>, mp_int<2>); + BOOST_TEST_TRAIT_SAME(mp_at>, mp_int<3>); + BOOST_TEST_TRAIT_SAME(mp_at>, mp_int<4>); + BOOST_TEST_TRAIT_SAME(mp_at>, mp_int<5>); + } + + return boost::report_errors(); +} + +#endif