diff --git a/include/boost/mp11/algorithm.hpp b/include/boost/mp11/algorithm.hpp index 73a15e7..8289be5 100644 --- a/include/boost/mp11/algorithm.hpp +++ b/include/boost/mp11/algorithm.hpp @@ -1229,6 +1229,17 @@ template class F, template class R> struct template using mp_iterate_q = mp_iterate; +// mp_pairwise_fold +namespace detail +{ + +template using mp_pairwise_fold_impl = mp_transform_q, mp_pop_front>; + +} // namespace detail + +template 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 mp11 } // namespace boost diff --git a/test/Jamfile b/test/Jamfile index ee42fd8..8e46ac5 100644 --- a/test/Jamfile +++ b/test/Jamfile @@ -122,6 +122,8 @@ run mp_rotate_right.cpp ; run mp_power_set.cpp ; run mp_partial_sum.cpp ; run mp_iterate.cpp ; +run mp_pairwise_fold.cpp ; +run mp_pairwise_fold_q.cpp ; # integral run integral.cpp ; diff --git a/test/mp_pairwise_fold.cpp b/test/mp_pairwise_fold.cpp new file mode 100644 index 0000000..48141a7 --- /dev/null +++ b/test/mp_pairwise_fold.cpp @@ -0,0 +1,49 @@ +// Copyright 2020 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 {}; + +template using is_same = typename std::is_same::type; + +int main() +{ + using boost::mp11::mp_list; + using boost::mp11::mp_pairwise_fold; + + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_list>, mp_list<>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_list>, mp_list<>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_list>, mp_list>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_list>, mp_list, mp_list>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_list>, mp_list, mp_list, mp_list>>)); + + BOOST_TEST_TRAIT_TRUE((std::is_same, std::pair>, mp_list<>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, std::pair>, mp_list<>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, std::pair>, mp_list>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, std::pair>, mp_list, std::pair>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, std::pair>, mp_list, std::pair, std::pair>>)); + + BOOST_TEST_TRAIT_TRUE((std::is_same, std::pair>, std::tuple<>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, std::pair>, std::tuple<>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, std::pair>, std::tuple>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, std::pair>, std::tuple, std::pair>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, std::pair>, std::tuple, std::pair, std::pair>>)); + + BOOST_TEST_TRAIT_TRUE((std::is_same, is_same>, std::tuple<>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, is_same>, std::tuple<>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, is_same>, std::tuple>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, is_same>, std::tuple, is_same>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, is_same>, std::tuple, is_same, is_same>>)); + + return boost::report_errors(); +} diff --git a/test/mp_pairwise_fold_q.cpp b/test/mp_pairwise_fold_q.cpp new file mode 100644 index 0000000..15e1b11 --- /dev/null +++ b/test/mp_pairwise_fold_q.cpp @@ -0,0 +1,18 @@ +// Copyright 2020 Peter Dimov +// Distributed under the Boost Software License, Version 1.0. +// https://www.boost.org/LICENSE_1_0.txt + +#include +#include + +using namespace boost::mp11; + +template using is_sorted = mp_none_of>, mp_to_bool>; + +int main() +{ + BOOST_TEST_TRAIT_TRUE((is_sorted, mp_int<0>, mp_int<1>, mp_int<3>, mp_int<3>, mp_int<7>>>)); + BOOST_TEST_TRAIT_FALSE((is_sorted, mp_int<0>, mp_int<1>, mp_int<3>, mp_int<3>, mp_int<2>>>)); + + return boost::report_errors(); +}