From b4c3f29917b94c1d2a499ed40316d6bfc4666f69 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Sun, 21 Jun 2015 20:47:04 +0300 Subject: [PATCH 1/5] Move algorithms to algorithm.hpp. --- include/boost/mp11.hpp | 1 + include/boost/mp11/algorithm.hpp | 188 +++++++++++++++++++++++++++++++ include/boost/mp11/list.hpp | 169 --------------------------- test/Jamfile.v2 | 3 + test/mp11.cpp | 14 +++ test/mp_assign.cpp | 1 + test/mp_clear.cpp | 1 + test/mp_fill.cpp | 1 + test/mp_repeat.cpp | 3 +- 9 files changed, 211 insertions(+), 170 deletions(-) create mode 100644 include/boost/mp11/algorithm.hpp create mode 100644 test/mp11.cpp diff --git a/include/boost/mp11.hpp b/include/boost/mp11.hpp index 32cbb01..e623917 100644 --- a/include/boost/mp11.hpp +++ b/include/boost/mp11.hpp @@ -9,6 +9,7 @@ // http://www.boost.org/LICENSE_1_0.txt #include +#include #include #include diff --git a/include/boost/mp11/algorithm.hpp b/include/boost/mp11/algorithm.hpp new file mode 100644 index 0000000..1111370 --- /dev/null +++ b/include/boost/mp11/algorithm.hpp @@ -0,0 +1,188 @@ +#ifndef BOOST_MP11_ALGORITHM_HPP_INCLUDED +#define BOOST_MP11_ALGORITHM_HPP_INCLUDED + +// 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 + +namespace boost +{ + +// mp_assign +namespace detail +{ + +template struct mp_assign_impl; + +template class L1, class... T, template class L2, class... U> struct mp_assign_impl, L2> +{ + using type = L1; +}; + +} // namespace detail + +template using mp_assign = typename detail::mp_assign_impl::type; + +// mp_clear +template using mp_clear = mp_assign>; + +// mp_transform +namespace detail +{ + +template class F, class... L> struct mp_transform_impl; + +template class F, class... L> using mp_transform = typename mp_transform_impl::type; + +template class F, template class L, class... T> struct mp_transform_impl> +{ + using type = L...>; +}; + +template class F, template class L1, class... T1, template class L2, class... T2> struct mp_transform_impl, L2> +{ + static_assert( sizeof...(T1) == sizeof...(T2), "The arguments of mp_transform should be of the same size" ); + using type = L1...>; +}; + +template class F, template class L1, class... T1, template class L2, class... T2, template class L3, class... T3> struct mp_transform_impl, L2, L3> +{ + static_assert( sizeof...(T1) == sizeof...(T2) && sizeof...(T1) == sizeof...(T3), "The arguments of mp_transform should be of the same size" ); + using type = L1...>; +}; + +} // namespace detail + +template class F, class... L> using mp_transform = typename detail::mp_transform_impl::type; + +// mp_fill +namespace detail +{ + +template struct mp_fill_impl; + +template class L, class... T, class V> struct mp_fill_impl, V> +{ +#if defined( BOOST_MSVC ) && BOOST_WORKAROUND( BOOST_MSVC, <= 1800 ) + + template struct _f { using type = V; }; + using type = L::type...>; + +#else + + template using _f = V; + using type = L<_f...>; + +#endif +}; + +} // namespace detail + +template using mp_fill = typename detail::mp_fill_impl::type; + +// mp_count +namespace detail +{ + +template struct mp_count_impl; + +template class L, class... T, class V> struct mp_count_impl, V> +{ + using type = mp_plus...>; +}; + +} // namespace detail + +template using mp_count = typename detail::mp_count_impl::type; + +// mp_count_if +namespace detail +{ + +template class P> struct mp_count_if_impl; + +template class L, class... T, template class P> struct mp_count_if_impl, P> +{ +#if defined( BOOST_MSVC ) && BOOST_WORKAROUND( BOOST_MSVC, <= 1800 ) + + template struct _f { using type = mp_to_bool>; }; + using type = mp_plus::type...>; + +#else + + using type = mp_plus>...>; + +#endif +}; + +} // namespace detail + +template class P> using mp_count_if = typename detail::mp_count_if_impl::type; + +// mp_contains +template using mp_contains = mp_to_bool>; + +// mp_repeat(_c) +namespace detail +{ + +template struct mp_repeat_c_impl +{ + using _l1 = typename mp_repeat_c_impl::type; + using _l2 = typename mp_repeat_c_impl::type; + + using type = mp_append<_l1, _l1, _l2>; +}; + +template struct mp_repeat_c_impl +{ + using type = mp_clear; +}; + +template struct mp_repeat_c_impl +{ + using type = L; +}; + +template struct mp_repeat_impl +{ + static_assert( N::value >= 0, "mp_repeat: N must not be negative" ); + + using type = typename mp_repeat_c_impl::type; +}; + +} // namespace detail + +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_find +// mp_find_if +// mp_find_index +// mp_find_index_if +// mp_reverse +// mp_copy_if +// mp_remove_if +// mp_product? +// mp_fold +// mp_reverse_fold +// mp_replace? +// mp_replace_if? +// mp_partition +// mp_sort + +} // namespace boost + +#endif // #ifndef BOOST_MP11_ALGORITHM_HPP_INCLUDED diff --git a/include/boost/mp11/list.hpp b/include/boost/mp11/list.hpp index d13d2b2..ecc672e 100644 --- a/include/boost/mp11/list.hpp +++ b/include/boost/mp11/list.hpp @@ -9,10 +9,6 @@ // http://www.boost.org/LICENSE_1_0.txt #include -#include -#include -#include -#include namespace boost { @@ -176,171 +172,6 @@ template class L1, class... T1, template class L2, template using mp_append = typename detail::mp_append_impl::type; -// mp_assign -namespace detail -{ - -template struct mp_assign_impl; - -template class L1, class... T, template class L2, class... U> struct mp_assign_impl, L2> -{ - using type = L1; -}; - -} // namespace detail - -template using mp_assign = typename detail::mp_assign_impl::type; - -// mp_clear -template using mp_clear = mp_assign>; - -// mp_transform -namespace detail -{ - -template class F, class... L> struct mp_transform_impl; - -template class F, class... L> using mp_transform = typename mp_transform_impl::type; - -template class F, template class L, class... T> struct mp_transform_impl> -{ - using type = L...>; -}; - -template class F, template class L1, class... T1, template class L2, class... T2> struct mp_transform_impl, L2> -{ - static_assert( sizeof...(T1) == sizeof...(T2), "The arguments of mp_transform should be of the same size" ); - using type = L1...>; -}; - -template class F, template class L1, class... T1, template class L2, class... T2, template class L3, class... T3> struct mp_transform_impl, L2, L3> -{ - static_assert( sizeof...(T1) == sizeof...(T2) && sizeof...(T1) == sizeof...(T3), "The arguments of mp_transform should be of the same size" ); - using type = L1...>; -}; - -} // namespace detail - -template class F, class... L> using mp_transform = typename detail::mp_transform_impl::type; - -// mp_fill -namespace detail -{ - -template struct mp_fill_impl; - -template class L, class... T, class V> struct mp_fill_impl, V> -{ -#if defined( BOOST_MSVC ) && BOOST_WORKAROUND( BOOST_MSVC, <= 1800 ) - - template struct _f { using type = V; }; - using type = L::type...>; - -#else - - template using _f = V; - using type = L<_f...>; - -#endif -}; - -} // namespace detail - -template using mp_fill = typename detail::mp_fill_impl::type; - -// mp_count -namespace detail -{ - -template struct mp_count_impl; - -template class L, class... T, class V> struct mp_count_impl, V> -{ - using type = mp_plus...>; -}; - -} // namespace detail - -template using mp_count = typename detail::mp_count_impl::type; - -// mp_count_if -namespace detail -{ - -template class P> struct mp_count_if_impl; - -template class L, class... T, template class P> struct mp_count_if_impl, P> -{ -#if defined( BOOST_MSVC ) && BOOST_WORKAROUND( BOOST_MSVC, <= 1800 ) - - template struct _f { using type = mp_to_bool>; }; - using type = mp_plus::type...>; - -#else - - using type = mp_plus>...>; - -#endif -}; - -} // namespace detail - -template class P> using mp_count_if = typename detail::mp_count_if_impl::type; - -// mp_contains -template using mp_contains = mp_to_bool>; - -// mp_repeat(_c) -namespace detail -{ - -template struct mp_repeat_c_impl -{ - using _l1 = typename mp_repeat_c_impl::type; - using _l2 = typename mp_repeat_c_impl::type; - - using type = mp_append<_l1, _l1, _l2>; -}; - -template struct mp_repeat_c_impl -{ - using type = mp_clear; -}; - -template struct mp_repeat_c_impl -{ - using type = L; -}; - -template struct mp_repeat_impl -{ - static_assert( N::value >= 0, "mp_repeat: N must not be negative" ); - - using type = typename mp_repeat_c_impl::type; -}; - -} // namespace detail - -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_find -// mp_find_if -// mp_find_index -// mp_find_index_if -// mp_reverse -// mp_copy_if -// mp_remove_if -// mp_product? -// mp_fold -// mp_reverse_fold -// mp_replace? -// mp_replace_if? -// mp_partition -// mp_sort - } // namespace boost #endif // #ifndef BOOST_MP11_LIST_HPP_INCLUDED diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 249e876..3f3d35a 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -11,6 +11,9 @@ import ../../config/checks/config : requires ; REQ = ; #[ requires cxx11_variadic_templates cxx11_template_aliases cxx11_hdr_type_traits cxx11_hdr_tuple ] ; +# include-only +compile mp11.cpp : : : $(REQ) ; + # list run mp_size.cpp : : : $(REQ) ; run mp_empty.cpp : : : $(REQ) ; diff --git a/test/mp11.cpp b/test/mp11.cpp new file mode 100644 index 0000000..6ab26cb --- /dev/null +++ b/test/mp11.cpp @@ -0,0 +1,14 @@ + +// 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 + +int main() +{ +} diff --git a/test/mp_assign.cpp b/test/mp_assign.cpp index a586cf5..cd6bea5 100644 --- a/test/mp_assign.cpp +++ b/test/mp_assign.cpp @@ -8,6 +8,7 @@ #include +#include #include #include #include diff --git a/test/mp_clear.cpp b/test/mp_clear.cpp index e3fb626..991d5a5 100644 --- a/test/mp_clear.cpp +++ b/test/mp_clear.cpp @@ -8,6 +8,7 @@ #include +#include #include #include #include diff --git a/test/mp_fill.cpp b/test/mp_fill.cpp index b2fdf81..e12f538 100644 --- a/test/mp_fill.cpp +++ b/test/mp_fill.cpp @@ -8,6 +8,7 @@ #include +#include #include #include #include diff --git a/test/mp_repeat.cpp b/test/mp_repeat.cpp index 3f08a50..a145fc8 100644 --- a/test/mp_repeat.cpp +++ b/test/mp_repeat.cpp @@ -7,9 +7,10 @@ // http://www.boost.org/LICENSE_1_0.txt -#include +#include #include #include +#include #include #include #include From 894f6cf129dbe8deb7f1b236583ae59fd3577e20 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Sun, 21 Jun 2015 21:12:28 +0300 Subject: [PATCH 2/5] Add test for mp_transform. --- test/Jamfile.v2 | 2 +- test/mp_transform.cpp | 85 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 test/mp_transform.cpp diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 3f3d35a..dc71979 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -27,7 +27,7 @@ run mp_rename.cpp : : : $(REQ) ; run mp_append.cpp : : : $(REQ) ; run mp_assign.cpp : : : $(REQ) ; run mp_clear.cpp : : : $(REQ) ; -#run mp_transform.cpp : : : $(REQ) ; +run mp_transform.cpp : : : $(REQ) ; run mp_fill.cpp : : : $(REQ) ; #run mp_count.cpp : : : $(REQ) ; #run mp_count_if.cpp : : : $(REQ) ; diff --git a/test/mp_transform.cpp b/test/mp_transform.cpp new file mode 100644 index 0000000..3d17a16 --- /dev/null +++ b/test/mp_transform.cpp @@ -0,0 +1,85 @@ + +// 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 X4 {}; + +struct Y1 {}; +struct Y2 {}; +struct Y3 {}; +struct Y4 {}; + +struct Z1 {}; +struct Z2 {}; +struct Z3 {}; +struct Z4 {}; + +template using add_pointer = typename std::add_pointer::type; +template using is_same = typename std::is_same::type; + +int main() +{ + using boost::mp_list; + using boost::mp_transform; + + using L1 = mp_list; + + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_list, mp_list, mp_list, mp_list>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_list, std::tuple, std::tuple, std::tuple>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_list, std::add_pointer, std::add_pointer, std::add_pointer>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_list>)); + + using L2 = std::tuple; + + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_list, mp_list, mp_list, mp_list>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_list, std::tuple, std::tuple, std::tuple>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_list, std::pair, std::pair, std::pair>>)); + + using L3 = mp_list; + + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_list, mp_list, mp_list, mp_list>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_list, std::tuple, std::tuple, std::tuple>>)); + + // + + using L4 = std::tuple; + + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_list>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_list>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_list>)); + + // + + using L5 = std::pair; + using L6 = std::pair; + using L7 = std::pair; + + 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>)); + + BOOST_TEST_TRAIT_TRUE((std::is_same, std::pair>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, std::pair>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, std::pair>)); + + // + + return boost::report_errors(); +} From 138e4de0a8767636ab1ac4fbf289bd54090e9e4c Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Mon, 22 Jun 2015 00:06:50 +0300 Subject: [PATCH 3/5] Add tests for mp_count, mp_count_if. --- include/boost/mp11/algorithm.hpp | 38 ++++++++++++++-- include/boost/mp11/detail/mp_plus.hpp | 32 +++----------- test/Jamfile.v2 | 4 +- test/mp_count.cpp | 63 +++++++++++++++++++++++++++ test/mp_count_if.cpp | 59 +++++++++++++++++++++++++ 5 files changed, 164 insertions(+), 32 deletions(-) create mode 100644 test/mp_count.cpp create mode 100644 test/mp_count_if.cpp diff --git a/include/boost/mp11/algorithm.hpp b/include/boost/mp11/algorithm.hpp index 1111370..6a72a52 100644 --- a/include/boost/mp11/algorithm.hpp +++ b/include/boost/mp11/algorithm.hpp @@ -96,11 +96,32 @@ namespace detail template struct mp_count_impl; +#if !defined( BOOST_NO_CXX11_CONSTEXPR ) + +constexpr std::size_t cx_plus() +{ + return 0; +} + +template constexpr std::size_t cx_plus(T1 t1, T... t) +{ + return t1 + cx_plus(t...); +} + template class L, class... T, class V> struct mp_count_impl, V> { - using type = mp_plus...>; + using type = mp_size_t::value...)>; }; +#else + +template class L, class... T, class V> struct mp_count_impl, V> +{ + using type = mp_size_t...>::value>; +}; + +#endif + } // namespace detail template using mp_count = typename detail::mp_count_impl::type; @@ -111,20 +132,31 @@ namespace detail template class P> struct mp_count_if_impl; +#if !defined( BOOST_NO_CXX11_CONSTEXPR ) + +template class L, class... T, template class P> struct mp_count_if_impl, P> +{ + using type = mp_size_t>::value...)>; +}; + +#else + template class L, class... T, template class P> struct mp_count_if_impl, P> { #if defined( BOOST_MSVC ) && BOOST_WORKAROUND( BOOST_MSVC, <= 1800 ) template struct _f { using type = mp_to_bool>; }; - using type = mp_plus::type...>; + using type = mp_size_t::type...>::value>; #else - using type = mp_plus>...>; + using type = mp_size_t>...>::value>; #endif }; +#endif + } // namespace detail template class P> using mp_count_if = typename detail::mp_count_if_impl::type; diff --git a/include/boost/mp11/detail/mp_plus.hpp b/include/boost/mp11/detail/mp_plus.hpp index 1b77783..88e34ef 100644 --- a/include/boost/mp11/detail/mp_plus.hpp +++ b/include/boost/mp11/detail/mp_plus.hpp @@ -20,45 +20,23 @@ namespace detail template struct mp_plus_impl; -#if defined( BOOST_NO_CXX11_CONSTEXPR ) - template<> struct mp_plus_impl<> { - using type = std::integral_constant; + using type = std::integral_constant; }; template struct mp_plus_impl { - static const/*expr*/ auto _v = T1::value + mp_plus::value; - using type = std::integral_constant< typename std::remove_const::type, _v >; + static const/*expr*/ auto _v = T1::value + mp_plus_impl::type::value; + using type = std::integral_constant::type, _v>; }; template struct mp_plus_impl { - static const/*expr*/ auto _v = T1::value + T2::value + T3::value + T4::value + T5::value + T6::value + T7::value + T8::value + T9::value + T10::value + mp_plus::value; - using type = std::integral_constant< typename std::remove_const::type, _v >; + static const/*expr*/ auto _v = T1::value + T2::value + T3::value + T4::value + T5::value + T6::value + T7::value + T8::value + T9::value + T10::value + mp_plus_impl::type::value; + using type = std::integral_constant::type, _v>; }; -#else - -constexpr int cx_plus() -{ - return 0; -} - -template constexpr auto cx_plus( T1 t1, T... t ) -> decltype( t1 + cx_plus( t... ) ) -{ - return t1 + cx_plus( t... ); -} - -template struct mp_plus_impl -{ - static constexpr auto _v = cx_plus( T::value... ); - using type = std::integral_constant< typename std::remove_const::type, _v >; -}; - -#endif - } // namespace detail template using mp_plus = typename detail::mp_plus_impl::type; diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index dc71979..4cd6c40 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -29,8 +29,8 @@ run mp_assign.cpp : : : $(REQ) ; run mp_clear.cpp : : : $(REQ) ; run mp_transform.cpp : : : $(REQ) ; run mp_fill.cpp : : : $(REQ) ; -#run mp_count.cpp : : : $(REQ) ; -#run mp_count_if.cpp : : : $(REQ) ; +run mp_count.cpp : : : $(REQ) ; +run mp_count_if.cpp : : : $(REQ) ; #run mp_contains.cpp : : : $(REQ) ; run mp_repeat.cpp : : : $(REQ) ; diff --git a/test/mp_count.cpp b/test/mp_count.cpp new file mode 100644 index 0000000..15c128a --- /dev/null +++ b/test/mp_count.cpp @@ -0,0 +1,63 @@ + +// 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 +#include + +struct X1 {}; +struct X2 {}; +struct X3 {}; + +int main() +{ + using boost::mp_list; + using boost::mp_count; + using boost::mp_size_t; + + { + using L1 = mp_list<>; + + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_size_t<0>>)); + + using L2 = mp_list; + + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_size_t<0>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_size_t<1>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_size_t<2>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_size_t<3>>)); + } + + { + using L3 = std::tuple<>; + + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_size_t<0>>)); + + using L4 = std::tuple; + + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_size_t<0>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_size_t<1>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_size_t<2>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_size_t<3>>)); + } + + { + using L5 = std::pair; + + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_size_t<0>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_size_t<1>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_size_t<1>>)); + } + + return boost::report_errors(); +} diff --git a/test/mp_count_if.cpp b/test/mp_count_if.cpp new file mode 100644 index 0000000..311cf12 --- /dev/null +++ b/test/mp_count_if.cpp @@ -0,0 +1,59 @@ + +// 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 +#include + +struct X1 {}; + +int main() +{ + using boost::mp_list; + using boost::mp_count_if; + using boost::mp_size_t; + + { + using L1 = mp_list<>; + + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_size_t<0>>)); + + using L2 = mp_list; + + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_size_t<0>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_size_t<2>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_size_t<3>>)); + } + + { + using L1 = std::tuple<>; + + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_size_t<0>>)); + + using L2 = std::tuple; + + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_size_t<0>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_size_t<2>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_size_t<3>>)); + } + + { + using L2 = std::pair; + + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_size_t<0>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_size_t<1>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_size_t<1>>)); + } + + return boost::report_errors(); +} From 782894ebfbde281401092bd89b1a2f9cceafc3c9 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Mon, 22 Jun 2015 00:10:24 +0300 Subject: [PATCH 4/5] Add test for mp_contains. --- test/Jamfile.v2 | 2 +- test/mp_contains.cpp | 64 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 test/mp_contains.cpp diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 4cd6c40..eb3e20c 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -31,7 +31,7 @@ run mp_transform.cpp : : : $(REQ) ; run mp_fill.cpp : : : $(REQ) ; run mp_count.cpp : : : $(REQ) ; run mp_count_if.cpp : : : $(REQ) ; -#run mp_contains.cpp : : : $(REQ) ; +run mp_contains.cpp : : : $(REQ) ; run mp_repeat.cpp : : : $(REQ) ; # integral diff --git a/test/mp_contains.cpp b/test/mp_contains.cpp new file mode 100644 index 0000000..deef491 --- /dev/null +++ b/test/mp_contains.cpp @@ -0,0 +1,64 @@ + +// 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 +#include + +struct X1 {}; +struct X2 {}; +struct X3 {}; + +int main() +{ + using boost::mp_list; + using boost::mp_contains; + using boost::mp_true; + using boost::mp_false; + + { + using L1 = mp_list<>; + + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_false>)); + + using L2 = mp_list; + + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_false>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_true>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_true>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_true>)); + } + + { + using L3 = std::tuple<>; + + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_false>)); + + using L4 = std::tuple; + + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_false>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_true>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_true>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_true>)); + } + + { + using L5 = std::pair; + + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_false>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_true>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_true>)); + } + + return boost::report_errors(); +} From d5f6ca8eb6b32e6caa74c698af46a95cdac3afa8 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Mon, 22 Jun 2015 00:46:24 +0300 Subject: [PATCH 5/5] Add mp_product. --- include/boost/mp11/algorithm.hpp | 34 ++++++++++++++++++++-- test/Jamfile.v2 | 1 + test/mp_product.cpp | 50 ++++++++++++++++++++++++++++++++ 3 files changed, 82 insertions(+), 3 deletions(-) create mode 100644 test/mp_product.cpp 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(); +}