From 080c3437edbc8ddf7332d4786ff4b08f6e10b008 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Fri, 12 Mar 2021 04:27:50 +0200 Subject: [PATCH] Add mp_intersperse --- include/boost/mp11/algorithm.hpp | 21 ++++++++++++++++++ test/Jamfile | 1 + test/mp_intersperse.cpp | 38 ++++++++++++++++++++++++++++++++ 3 files changed, 60 insertions(+) create mode 100644 test/mp_intersperse.cpp diff --git a/include/boost/mp11/algorithm.hpp b/include/boost/mp11/algorithm.hpp index 8289be5..1b94f7e 100644 --- a/include/boost/mp11/algorithm.hpp +++ b/include/boost/mp11/algorithm.hpp @@ -1240,6 +1240,27 @@ template using mp_pairwise_fold_impl = mp_transform_q using mp_pairwise_fold_q = mp_eval_if, mp_clear, detail::mp_pairwise_fold_impl, L, Q>; template class F> using mp_pairwise_fold = mp_pairwise_fold_q>; +namespace detail +{ + +template struct mp_intersperse_impl +{ +}; + +template class L, class S> struct mp_intersperse_impl, S> +{ + using type = L<>; +}; + +template class L, class T1, class... T, class S> struct mp_intersperse_impl, S> +{ + using type = mp_append, L...>; +}; + +} // namespace detail + +template using mp_intersperse = typename detail::mp_intersperse_impl::type; + } // namespace mp11 } // namespace boost diff --git a/test/Jamfile b/test/Jamfile index 8e46ac5..25e7d6b 100644 --- a/test/Jamfile +++ b/test/Jamfile @@ -124,6 +124,7 @@ run mp_partial_sum.cpp ; run mp_iterate.cpp ; run mp_pairwise_fold.cpp ; run mp_pairwise_fold_q.cpp ; +run mp_intersperse.cpp ; # integral run integral.cpp ; diff --git a/test/mp_intersperse.cpp b/test/mp_intersperse.cpp new file mode 100644 index 0000000..5a5ef16 --- /dev/null +++ b/test/mp_intersperse.cpp @@ -0,0 +1,38 @@ +// Copyright 2021 Peter Dimov +// Distributed under the Boost Software License, Version 1.0. +// https://www.boost.org/LICENSE_1_0.txt + +#include +#include +#include +#include +#include +#include + +struct X1 {}; +struct X2 {}; +struct X3 {}; +struct X4 {}; +struct X5 {}; + +int main() +{ + using boost::mp11::mp_list; + using boost::mp11::mp_intersperse; + + BOOST_TEST_TRAIT_TRUE((std::is_same, void>, mp_list<>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, void>, mp_list>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, void>, mp_list>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, void>, mp_list>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, void>, mp_list>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, void>, mp_list>)); + + BOOST_TEST_TRAIT_TRUE((std::is_same, void>, std::tuple<>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, void>, std::tuple>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, void>, std::tuple>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, void>, std::tuple>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, void>, std::tuple>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, void>, std::tuple>)); + + return boost::report_errors(); +}