mirror of
https://github.com/boostorg/mp11.git
synced 2025-08-05 23:34:34 +02:00
Add mp_intersperse
This commit is contained in:
@@ -1240,6 +1240,27 @@ template<class L, class Q> using mp_pairwise_fold_impl = mp_transform_q<Q, mp_po
|
|||||||
template<class L, class Q> using mp_pairwise_fold_q = mp_eval_if<mp_empty<L>, mp_clear<L>, detail::mp_pairwise_fold_impl, L, Q>;
|
template<class L, class Q> using mp_pairwise_fold_q = mp_eval_if<mp_empty<L>, mp_clear<L>, detail::mp_pairwise_fold_impl, L, Q>;
|
||||||
template<class L, template<class...> class F> using mp_pairwise_fold = mp_pairwise_fold_q<L, mp_quote<F>>;
|
template<class L, template<class...> class F> using mp_pairwise_fold = mp_pairwise_fold_q<L, mp_quote<F>>;
|
||||||
|
|
||||||
|
namespace detail
|
||||||
|
{
|
||||||
|
|
||||||
|
template<class L, class S> struct mp_intersperse_impl
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
|
template<template<class...> class L, class S> struct mp_intersperse_impl<L<>, S>
|
||||||
|
{
|
||||||
|
using type = L<>;
|
||||||
|
};
|
||||||
|
|
||||||
|
template<template<class...> class L, class T1, class... T, class S> struct mp_intersperse_impl<L<T1, T...>, S>
|
||||||
|
{
|
||||||
|
using type = mp_append<L<T1>, L<S, T>...>;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace detail
|
||||||
|
|
||||||
|
template<class L, class S> using mp_intersperse = typename detail::mp_intersperse_impl<L, S>::type;
|
||||||
|
|
||||||
} // namespace mp11
|
} // namespace mp11
|
||||||
} // namespace boost
|
} // namespace boost
|
||||||
|
|
||||||
|
@@ -124,6 +124,7 @@ run mp_partial_sum.cpp ;
|
|||||||
run mp_iterate.cpp ;
|
run mp_iterate.cpp ;
|
||||||
run mp_pairwise_fold.cpp ;
|
run mp_pairwise_fold.cpp ;
|
||||||
run mp_pairwise_fold_q.cpp ;
|
run mp_pairwise_fold_q.cpp ;
|
||||||
|
run mp_intersperse.cpp ;
|
||||||
|
|
||||||
# integral
|
# integral
|
||||||
run integral.cpp ;
|
run integral.cpp ;
|
||||||
|
38
test/mp_intersperse.cpp
Normal file
38
test/mp_intersperse.cpp
Normal file
@@ -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 <boost/mp11/algorithm.hpp>
|
||||||
|
#include <boost/mp11/list.hpp>
|
||||||
|
#include <boost/core/lightweight_test_trait.hpp>
|
||||||
|
#include <type_traits>
|
||||||
|
#include <tuple>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
|
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<mp_intersperse<mp_list<>, void>, mp_list<>>));
|
||||||
|
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_intersperse<mp_list<X1>, void>, mp_list<X1>>));
|
||||||
|
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_intersperse<mp_list<X1, X2>, void>, mp_list<X1, void, X2>>));
|
||||||
|
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_intersperse<mp_list<X1, X2, X3>, void>, mp_list<X1, void, X2, void, X3>>));
|
||||||
|
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_intersperse<mp_list<X1, X2, X3, X4>, void>, mp_list<X1, void, X2, void, X3, void, X4>>));
|
||||||
|
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_intersperse<mp_list<X1, X2, X3, X4, X5>, void>, mp_list<X1, void, X2, void, X3, void, X4, void, X5>>));
|
||||||
|
|
||||||
|
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_intersperse<std::tuple<>, void>, std::tuple<>>));
|
||||||
|
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_intersperse<std::tuple<X1>, void>, std::tuple<X1>>));
|
||||||
|
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_intersperse<std::tuple<X1, X2>, void>, std::tuple<X1, void, X2>>));
|
||||||
|
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_intersperse<std::tuple<X1, X2, X3>, void>, std::tuple<X1, void, X2, void, X3>>));
|
||||||
|
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_intersperse<std::tuple<X1, X2, X3, X4>, void>, std::tuple<X1, void, X2, void, X3, void, X4>>));
|
||||||
|
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_intersperse<std::tuple<X1, X2, X3, X4, X5>, void>, std::tuple<X1, void, X2, void, X3, void, X4, void, X5>>));
|
||||||
|
|
||||||
|
return boost::report_errors();
|
||||||
|
}
|
Reference in New Issue
Block a user