diff --git a/include/boost/mp11/algorithm.hpp b/include/boost/mp11/algorithm.hpp index 4e4ff7f..6ffc572 100644 --- a/include/boost/mp11/algorithm.hpp +++ b/include/boost/mp11/algorithm.hpp @@ -519,6 +519,19 @@ template using mp_remove = typename detail::mp_remove_impl // in detail/mp_remove_if.hpp +// mp_flatten> +namespace detail +{ + +template struct mp_flatten_impl +{ + template using fn = mp_if, T, mp_list>; +}; + +} // namespace detail + +template> using mp_flatten = mp_apply, L>, mp_clear>>; + // mp_partition namespace detail { diff --git a/test/Jamfile b/test/Jamfile index 542221f..440bd9e 100644 --- a/test/Jamfile +++ b/test/Jamfile @@ -116,6 +116,7 @@ run mp_nth_element.cpp ; run mp_nth_element_q.cpp ; run mp_back.cpp ; run mp_pop_back.cpp ; +run mp_flatten.cpp ; # integral run integral.cpp ; diff --git a/test/mp_flatten.cpp b/test/mp_flatten.cpp new file mode 100644 index 0000000..403b870 --- /dev/null +++ b/test/mp_flatten.cpp @@ -0,0 +1,101 @@ + +// Copyright 2019 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 + +int main() +{ + using boost::mp11::mp_list; + using boost::mp11::mp_flatten; + using boost::mp11::mp_transform; + + { + using L1 = mp_list<>; + using L2 = mp_list; + using L3 = mp_list; + + BOOST_TEST_TRAIT_TRUE((std::is_same, L1>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, L2>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, L3>)); + + BOOST_TEST_TRAIT_TRUE((std::is_same, L1>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, L2>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, L3>)); + + using L4 = mp_transform; + + BOOST_TEST_TRAIT_TRUE((std::is_same, L3>)); + BOOST_TEST_TRAIT_TRUE((std::is_same>, L3>)); + BOOST_TEST_TRAIT_TRUE((std::is_same>, L4>)); + + using L5 = mp_transform; + + BOOST_TEST_TRAIT_TRUE((std::is_same, L5>)); + BOOST_TEST_TRAIT_TRUE((std::is_same>, L5>)); + BOOST_TEST_TRAIT_TRUE((std::is_same>, L3>)); + } + + { + using L1 = std::tuple<>; + using L2 = std::tuple; + using L3 = std::tuple; + + BOOST_TEST_TRAIT_TRUE((std::is_same, L1>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, L2>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, L3>)); + + BOOST_TEST_TRAIT_TRUE((std::is_same, L1>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, L2>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, L3>)); + + using L4 = mp_transform; + + BOOST_TEST_TRAIT_TRUE((std::is_same, L4>)); + BOOST_TEST_TRAIT_TRUE((std::is_same>, L3>)); + BOOST_TEST_TRAIT_TRUE((std::is_same>, L4>)); + + using L5 = mp_transform; + + BOOST_TEST_TRAIT_TRUE((std::is_same, L3>)); + BOOST_TEST_TRAIT_TRUE((std::is_same>, L5>)); + BOOST_TEST_TRAIT_TRUE((std::is_same>, L3>)); + } + + { + using L1 = mp_list, int, mp_list<>, void, mp_list, std::pair>; + + using R1 = mp_flatten; + BOOST_TEST_TRAIT_TRUE((std::is_same, int, void, char, double, std::pair>>)); + + using R2 = mp_flatten>; + BOOST_TEST_TRAIT_TRUE((std::is_same, int, mp_list<>, void, mp_list, int, void>>)); + + using R3 = mp_flatten>; + BOOST_TEST_TRAIT_TRUE((std::is_same, void, mp_list, std::pair>>)); + } + + { + using L1 = std::tuple, int, mp_list<>, void, mp_list, std::pair>; + + using R1 = mp_flatten>; + BOOST_TEST_TRAIT_TRUE((std::is_same, int, void, char, double, std::pair>>)); + + using R2 = mp_flatten>; + BOOST_TEST_TRAIT_TRUE((std::is_same, int, mp_list<>, void, mp_list, int, void>>)); + + using R3 = mp_flatten; + BOOST_TEST_TRAIT_TRUE((std::is_same, void, mp_list, std::pair>>)); + } + + return boost::report_errors(); +}