From b7da04c5941968cd21f02e2dd9dd5174a87b4f28 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Sun, 14 May 2023 03:39:39 +0300 Subject: [PATCH] Add an offset parameter to mp_from_sequence --- include/boost/mp11/algorithm.hpp | 10 +++---- test/Jamfile | 1 + test/mp_from_sequence_2.cpp | 45 ++++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 5 deletions(-) create mode 100644 test/mp_from_sequence_2.cpp diff --git a/include/boost/mp11/algorithm.hpp b/include/boost/mp11/algorithm.hpp index 60987a8..d931457 100644 --- a/include/boost/mp11/algorithm.hpp +++ b/include/boost/mp11/algorithm.hpp @@ -308,20 +308,20 @@ template using mp_drop_c = typename detail::mp_drop_impl template using mp_drop = mp_drop_c; -// mp_from_sequence +// mp_from_sequence namespace detail { -template struct mp_from_sequence_impl; +template struct mp_from_sequence_impl; -template class S, class U, U... J> struct mp_from_sequence_impl> +template class S, class U, U... J, class F> struct mp_from_sequence_impl, F> { - using type = mp_list...>; + using type = mp_list_c; }; } // namespace detail -template using mp_from_sequence = typename detail::mp_from_sequence_impl::type; +template> using mp_from_sequence = typename detail::mp_from_sequence_impl::type; // mp_iota(_c) template using mp_iota_c = mp_from_sequence>; diff --git a/test/Jamfile b/test/Jamfile index f8344f6..661b801 100644 --- a/test/Jamfile +++ b/test/Jamfile @@ -109,6 +109,7 @@ run mp_erase.cpp ; run mp_with_index.cpp ; run mp_with_index_cx.cpp ; run mp_from_sequence.cpp ; +run mp_from_sequence_2.cpp ; run mp_min_element.cpp ; run mp_min_element_q.cpp ; run mp_max_element.cpp ; diff --git a/test/mp_from_sequence_2.cpp b/test/mp_from_sequence_2.cpp new file mode 100644 index 0000000..5e3538a --- /dev/null +++ b/test/mp_from_sequence_2.cpp @@ -0,0 +1,45 @@ +// Copyright 2017, 2023 Peter Dimov. +// Distributed under the Boost Software License, Version 1.0. +// https://www.boost.org/LICENSE_1_0.txt + +#include +#include +#include +#include +#include + +template struct S; + +template using mp_char = std::integral_constant; + +int main() +{ + using boost::mp11::mp_list; + using boost::mp11::mp_list_c; + using boost::mp11::mp_from_sequence; + using boost::mp11::mp_int; + using boost::mp11::mp_size_t; + using boost::mp11::make_integer_sequence; + using boost::mp11::make_index_sequence; + + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_int<-3>>, mp_list<>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_int<-3>>, mp_list>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_int<-3>>, mp_list, mp_int<0>>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_int<-3>>, mp_list, mp_int<0>, mp_int<+2>>>)); + + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_int<'0'>>, mp_list_c>)); + + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_int<-3>>, mp_list<>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_int<-3>>, mp_list>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_int<-3>>, mp_list, mp_int<-2>>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_int<-3>>, mp_list, mp_int<-2>, mp_int<-1>>>)); + + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_size_t<'0'>>, mp_list_c>)); + + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_int<4>>, mp_list<>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_int<4>>, mp_list>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_int<4>>, mp_list, mp_size_t<5>>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_int<4>>, mp_list, mp_size_t<5>, mp_size_t<6>>>)); + + return boost::report_errors(); +}