diff --git a/include/boost/mp11/algorithm.hpp b/include/boost/mp11/algorithm.hpp index 6a72a52..988d3f8 100644 --- a/include/boost/mp11/algorithm.hpp +++ b/include/boost/mp11/algorithm.hpp @@ -198,8 +198,37 @@ template struct mp_repeat_impl template using mp_repeat_c = typename detail::mp_repeat_c_impl::type; template using mp_repeat = typename detail::mp_repeat_impl::type; -// mp_drop -// mp_take +// mp_product + +namespace detail +{ + +template class F, class P, class... L> struct mp_product_impl_2; + +template class F, class P> struct mp_product_impl_2 +{ + using type = mp_list>; +}; + +template class F, class P, template class L1, class... T1, class... L> struct mp_product_impl_2, L...> +{ + using type = mp_append, L...>::type...>; +}; + +template class F, class... L> struct mp_product_impl; + +template class F, class L1, class... L> struct mp_product_impl +{ + using type = mp_assign, L1, L...>::type>; +}; + +} // namespace detail + +template class F, class... L> using mp_product = typename detail::mp_product_impl::type; + +// mp_drop(_c) +// mp_take(_c) +// mp_at(_c) // mp_find // mp_find_if // mp_find_index @@ -207,7 +236,6 @@ template using mp_repeat = typename detail::mp_repeat_impl // mp_copy_if // mp_remove_if -// mp_product? // mp_fold // mp_reverse_fold // mp_replace? diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index eb3e20c..ec31f1c 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -33,6 +33,7 @@ run mp_count.cpp : : : $(REQ) ; run mp_count_if.cpp : : : $(REQ) ; run mp_contains.cpp : : : $(REQ) ; run mp_repeat.cpp : : : $(REQ) ; +run mp_product.cpp : : : $(REQ) ; # integral run integral.cpp : : : $(REQ) ; diff --git a/test/mp_product.cpp b/test/mp_product.cpp new file mode 100644 index 0000000..351ea38 --- /dev/null +++ b/test/mp_product.cpp @@ -0,0 +1,50 @@ + +// Copyright 2015 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 +#include + +struct X1 {}; +struct X2 {}; +struct X3 {}; + +struct Y1 {}; + +struct Z1 {}; +struct Z2 {}; + +template struct F {}; + +int main() +{ + using boost::mp_list; + using boost::mp_product; + + { + using L1 = std::tuple; + using L2 = mp_list; + using L3 = std::pair; + + BOOST_TEST_TRAIT_TRUE((std::is_same, std::tuple, F, F, F, F, F>>)); + } + + { + using L1 = std::tuple; + using L2 = mp_list<>; + using L3 = std::pair; + + BOOST_TEST_TRAIT_TRUE((std::is_same, std::tuple<>>)); + } + + return boost::report_errors(); +}