diff --git a/doc/mp11/algorithm.adoc b/doc/mp11/algorithm.adoc index ba0292b..3724eaa 100644 --- a/doc/mp11/algorithm.adoc +++ b/doc/mp11/algorithm.adoc @@ -297,6 +297,17 @@ As `mp_product`, but takes a quoted metafunction. Same as `mp_drop_c`, but with a type argument `N`. `N::value` must be a nonnegative number. +## mp_from_sequence + + template using mp_from_sequence = /*...*/ + +`mp_from_sequence` transforms an integer sequence produced by `make_integer_sequence` into an `mp_list` +of the corresponding `std::integral_constant` types. Given + + template struct S; + +`mp_from_sequence>` is an alias for `mp_list...>`. + ## mp_iota_c template using mp_iota_c = /*...*/; diff --git a/doc/mp11/list.adoc b/doc/mp11/list.adoc index 11d566c..b8050bf 100644 --- a/doc/mp11/list.adoc +++ b/doc/mp11/list.adoc @@ -21,6 +21,18 @@ http://www.boost.org/LICENSE_1_0.txt such as `std::tuple` or `std::variant`. Even `std::pair` can be used if the transformation does not alter the number of the elements in the list. +## mp_list_c + + template using mp_list_c = + mp_list...>; + +`mp_list_c` produces an `mp_list` of the `std::integral_constant` types corresponding to its integer template arguments. + +.Using mp_list_c +``` +using L1 = mp_list_c; // mp_list, mp_int<3>> +``` + ## mp_is_list template using mp_is_list = /*...*/; diff --git a/include/boost/mp11/algorithm.hpp b/include/boost/mp11/algorithm.hpp index 8edb750..bde8092 100644 --- a/include/boost/mp11/algorithm.hpp +++ b/include/boost/mp11/algorithm.hpp @@ -287,7 +287,7 @@ template using mp_drop_c = typename detail::mp_drop_impl template using mp_drop = typename detail::mp_drop_impl, N>>::type; -// mp_iota(_c) +// mp_from_sequence namespace detail { @@ -298,12 +298,13 @@ template class S, class U, U... J> struct mp_from_sequ using type = mp_list...>; }; -template using mp_from_sequence = typename mp_from_sequence_impl::type; - } // namespace detail -template using mp_iota_c = detail::mp_from_sequence>; -template using mp_iota = detail::mp_from_sequence::type, N::value>>; +template using mp_from_sequence = typename detail::mp_from_sequence_impl::type; + +// mp_iota(_c) +template using mp_iota_c = mp_from_sequence>; +template using mp_iota = mp_from_sequence::type, N::value>>; // mp_at(_c) namespace detail diff --git a/include/boost/mp11/list.hpp b/include/boost/mp11/list.hpp index 2d371a6..8db4679 100644 --- a/include/boost/mp11/list.hpp +++ b/include/boost/mp11/list.hpp @@ -13,12 +13,16 @@ #include #include #include +#include namespace boost { namespace mp11 { +// mp_list_c +template using mp_list_c = mp_list...>; + // mp_is_list namespace detail { diff --git a/test/Jamfile b/test/Jamfile index df030ed..c1ed138 100644 --- a/test/Jamfile +++ b/test/Jamfile @@ -31,6 +31,7 @@ run mp_replace_second.cpp ; run mp_replace_third.cpp ; run mp_apply_q.cpp ; run mp_is_list.cpp ; +run mp_list_c.cpp ; # algorithm run mp_assign.cpp ; @@ -74,6 +75,7 @@ run mp_insert.cpp ; run mp_erase.cpp ; run mp_with_index.cpp ; run mp_with_index_cx.cpp ; +run mp_from_sequence.cpp ; # integral run integral.cpp ; diff --git a/test/mp_from_sequence.cpp b/test/mp_from_sequence.cpp new file mode 100644 index 0000000..a06d928 --- /dev/null +++ b/test/mp_from_sequence.cpp @@ -0,0 +1,43 @@ + +// Copyright 2017 Peter Dimov. +// +// Distributed under the Boost Software License, Version 1.0. +// +// See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt + + +#include +#include +#include +#include +#include + +template struct S; + +int main() +{ + using boost::mp11::mp_list; + 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_list<>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same>, mp_list>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same>, mp_list, mp_int<3>>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same>, mp_list, mp_int<3>, mp_int<5>>>)); + + BOOST_TEST_TRAIT_TRUE((std::is_same>, mp_list<>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same>, mp_list>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same>, mp_list, mp_int<1>>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same>, mp_list, mp_int<1>, mp_int<2>>>)); + + BOOST_TEST_TRAIT_TRUE((std::is_same>, mp_list<>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same>, mp_list>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same>, mp_list, mp_size_t<1>>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same>, mp_list, mp_size_t<1>, mp_size_t<2>>>)); + + return boost::report_errors(); +} diff --git a/test/mp_list_c.cpp b/test/mp_list_c.cpp new file mode 100644 index 0000000..d6130eb --- /dev/null +++ b/test/mp_list_c.cpp @@ -0,0 +1,27 @@ + +// Copyright 2017 Peter Dimov. +// +// Distributed under the Boost Software License, Version 1.0. +// +// See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt + + +#include +#include +#include +#include + +int main() +{ + using boost::mp11::mp_list_c; + using boost::mp11::mp_list; + using boost::mp11::mp_int; + + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_list<>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_list>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_list, mp_int<3>>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_list, mp_int<3>, mp_int<5>>>)); + + return boost::report_errors(); +}