diff --git a/include/boost/mp11/algorithm.hpp b/include/boost/mp11/algorithm.hpp index 76f727e..e717368 100644 --- a/include/boost/mp11/algorithm.hpp +++ b/include/boost/mp11/algorithm.hpp @@ -1,7 +1,7 @@ #ifndef BOOST_MP11_ALGORITHM_HPP_INCLUDED #define BOOST_MP11_ALGORITHM_HPP_INCLUDED -// Copyright 2015 Peter Dimov. +// Copyright 2015, 2016 Peter Dimov. // // Distributed under the Boost Software License, Version 1.0. // @@ -12,7 +12,8 @@ #include #include #include -#include +#include +#include #include #include #include @@ -47,8 +48,6 @@ 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...>; @@ -95,77 +94,6 @@ template class L, class... T, class V> struct mp_fill_impl using mp_fill = typename detail::mp_fill_impl::type; -// mp_count -namespace detail -{ - -template struct mp_count_impl; - -#if !defined( BOOST_MP11_NO_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_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; - -// mp_count_if -namespace detail -{ - -template class P> struct mp_count_if_impl; - -#if !defined( BOOST_MP11_NO_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, <= 1900 ) - - template struct _f { using type = mp_to_bool>; }; - using type = mp_size_t::type...>::value>; - -#else - - using type = mp_size_t>...>::value>; - -#endif -}; - -#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>; @@ -796,13 +724,13 @@ template class L, class... T> struct mp_unique_impl> template using mp_unique = typename detail::mp_unique_impl::type; // mp_all_of -template class P> using mp_all_of = mp_equal_to< mp_count_if, mp_size >; +template class P> using mp_all_of = mp_bool< mp_count_if::value == mp_size::value >; // mp_none_of -template class P> using mp_none_of = mp_not< mp_count_if >; +template class P> using mp_none_of = mp_bool< mp_count_if::value == 0 >; // mp_any_of -template class P> using mp_any_of = mp_to_bool< mp_count_if >; +template class P> using mp_any_of = mp_bool< mp_count_if::value != 0 >; } // namespace boost diff --git a/include/boost/mp11/detail/mp_count.hpp b/include/boost/mp11/detail/mp_count.hpp new file mode 100644 index 0000000..8a6ada5 --- /dev/null +++ b/include/boost/mp11/detail/mp_count.hpp @@ -0,0 +1,92 @@ +#ifndef BOOST_MP11_DETAIL_MP_COUNT_HPP_INCLUDED +#define BOOST_MP11_DETAIL_MP_COUNT_HPP_INCLUDED + +// Copyright 2015, 2016 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 + +namespace boost +{ + +// mp_count +namespace detail +{ + +template struct mp_count_impl; + +#if !defined( BOOST_MP11_NO_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_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; + +// mp_count_if +namespace detail +{ + +template class P> struct mp_count_if_impl; + +#if !defined( BOOST_MP11_NO_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, <= 1900 ) + + template struct _f { using type = mp_to_bool>; }; + using type = mp_size_t::type...>::value>; + +#else + + using type = mp_size_t>...>::value>; + +#endif +}; + +#endif + +} // namespace detail + +template class P> using mp_count_if = typename detail::mp_count_if_impl::type; + +} // namespace boost + +#endif // #ifndef BOOST_MP11_DETAIL_MP_COUNT_HPP_INCLUDED diff --git a/include/boost/mp11/detail/mp_list.hpp b/include/boost/mp11/detail/mp_list.hpp new file mode 100644 index 0000000..e0e285a --- /dev/null +++ b/include/boost/mp11/detail/mp_list.hpp @@ -0,0 +1,21 @@ +#ifndef BOOST_MP11_DETAIL_MP_LIST_HPP_INCLUDED +#define BOOST_MP11_DETAIL_MP_LIST_HPP_INCLUDED + +// Copyright 2015, 2016 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 + +namespace boost +{ + +// mp_list +template struct mp_list +{ +}; + +} // namespace boost + +#endif // #ifndef BOOST_MP11_DETAIL_MP_LIST_HPP_INCLUDED diff --git a/include/boost/mp11/function.hpp b/include/boost/mp11/function.hpp index c78fe29..cefec1a 100644 --- a/include/boost/mp11/function.hpp +++ b/include/boost/mp11/function.hpp @@ -1,7 +1,7 @@ #ifndef BOOST_MP11_FUNCTION_HPP_INCLUDED #define BOOST_MP11_FUNCTION_HPP_INCLUDED -// Copyright 2015 Peter Dimov. +// Copyright 2015, 2016 Peter Dimov. // // Distributed under the Boost Software License, Version 1.0. // @@ -9,21 +9,71 @@ // http://www.boost.org/LICENSE_1_0.txt #include -#include +#include +#include +#include namespace boost { -// mp_not -template using mp_not = mp_bool< !T::value >; - // mp_equal_to template using mp_equal_to = mp_bool< T1::value == T2::value >; // mp_all +template using mp_all = mp_bool< mp_count_if< mp_list, mp_to_bool >::value == sizeof...(T) >; + // mp_and +namespace detail +{ + +template struct mp_and_impl; + +} // namespace detail + +template using mp_and = typename detail::mp_and_impl::type; + +namespace detail +{ + +template<> struct mp_and_impl<> +{ + using type = mp_true; +}; + +template struct mp_and_impl +{ + using type = mp_eval_if< mp_not, mp_false, mp_and, T... >; +}; + +} // namespace detail + // mp_any +template using mp_any = mp_bool< mp_count_if< mp_list, mp_to_bool >::value != 0 >; + // mp_or +namespace detail +{ + +template struct mp_or_impl; + +} // namespace detail + +template using mp_or = typename detail::mp_or_impl::type; + +namespace detail +{ + +template<> struct mp_or_impl<> +{ + using type = mp_false; +}; + +template struct mp_or_impl +{ + using type = mp_eval_if< T1, mp_true, mp_or, T... >; +}; + +} // namespace detail } // namespace boost diff --git a/include/boost/mp11/integral.hpp b/include/boost/mp11/integral.hpp index 7380f5a..ebe52b5 100644 --- a/include/boost/mp11/integral.hpp +++ b/include/boost/mp11/integral.hpp @@ -23,6 +23,9 @@ using mp_false = mp_bool; // mp_to_bool template using mp_to_bool = mp_bool( T::value )>; +// mp_not +template using mp_not = mp_bool< !T::value >; + // mp_int template using mp_int = std::integral_constant; diff --git a/include/boost/mp11/list.hpp b/include/boost/mp11/list.hpp index ecc672e..6f09d25 100644 --- a/include/boost/mp11/list.hpp +++ b/include/boost/mp11/list.hpp @@ -9,15 +9,11 @@ // http://www.boost.org/LICENSE_1_0.txt #include +#include namespace boost { -// mp_list -template struct mp_list -{ -}; - // mp_size namespace detail { diff --git a/include/boost/mp11/map.hpp b/include/boost/mp11/map.hpp index 8c5afc3..92c5164 100644 --- a/include/boost/mp11/map.hpp +++ b/include/boost/mp11/map.hpp @@ -1,21 +1,52 @@ #ifndef BOOST_MP11_MAP_HPP_INCLUDED #define BOOST_MP11_MAP_HPP_INCLUDED -// Copyright 2015 Peter Dimov. +// Copyright 2015, 2016 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_map_find // mp_map_contains +template using mp_map_contains = mp_not, void>>; + // mp_map_insert +template using mp_map_insert = mp_if< mp_map_contains>, M, mp_push_back >; + // mp_map_replace +namespace detail +{ + +template struct mp_map_replace_impl; + +template class M, class... U, class T> struct mp_map_replace_impl, T> +{ + using K = mp_first; + + // mp_replace_if is inlined here using a struct _f because of msvc-14.0 + + template struct _f { using type = mp_if< std::is_same, K>, T, V >; }; + + using type = mp_if< mp_map_contains, K>, M::type...>, M >; +}; + +} // namespace detail + +template using mp_map_replace = typename detail::mp_map_replace_impl::type; + // mp_map_update +// mp_map_erase } // namespace boost diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 1457fdf..6d2c767 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -82,3 +82,15 @@ run tuple_for_each_cx.cpp : : : $(REQ) ; run mp_set_contains.cpp : : : $(REQ) ; run mp_set_push_back.cpp : : : $(REQ) ; run mp_set_push_front.cpp : : : $(REQ) ; + +# function +run mp_all.cpp : : : $(REQ) ; +run mp_and.cpp : : : $(REQ) ; +run mp_any.cpp : : : $(REQ) ; +run mp_or.cpp : : : $(REQ) ; + +# map +run mp_map_find.cpp : : : $(REQ) ; +run mp_map_contains.cpp : : : $(REQ) ; +run mp_map_insert.cpp : : : $(REQ) ; +run mp_map_replace.cpp : : : $(REQ) ; diff --git a/test/integral.cpp b/test/integral.cpp index 6935aad..82002b5 100644 --- a/test/integral.cpp +++ b/test/integral.cpp @@ -51,5 +51,20 @@ int main() BOOST_TEST_TRAIT_TRUE((std::is_same>, mp_true>)); BOOST_TEST_TRAIT_TRUE((std::is_same>, mp_true>)); + using boost::mp_not; + + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_true>)); + 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_false>)); + BOOST_TEST_TRAIT_TRUE((std::is_same>, mp_false>)); + BOOST_TEST_TRAIT_TRUE((std::is_same>, mp_false>)); + 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_false>)); + BOOST_TEST_TRAIT_TRUE((std::is_same>, mp_false>)); + return boost::report_errors(); } diff --git a/test/mp_all.cpp b/test/mp_all.cpp new file mode 100644 index 0000000..651c208 --- /dev/null +++ b/test/mp_all.cpp @@ -0,0 +1,57 @@ + +// Copyright 2015, 2016 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 + +int main() +{ + using boost::mp_all; + using boost::mp_true; + using boost::mp_false; + using boost::mp_int; + using boost::mp_size_t; + + 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_false>)); + + BOOST_TEST_TRAIT_TRUE((std::is_same>, mp_true>)); + 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_false>)); + + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_true>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_false>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_false>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_false>)); + + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_int<7>>, mp_true>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_size_t<1>>, mp_true>)); + + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_true>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_false>)); + 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_false>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_false>)); + + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_int<2>, mp_int<-11>, mp_int<14>>, mp_true>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_int<0>, mp_int<-11>, mp_int<14>>, mp_false>)); + + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_size_t<2>, mp_size_t<114>, mp_size_t<8>, mp_size_t<94>>, mp_true>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_size_t<2>, mp_size_t<114>, mp_size_t<0>, mp_size_t<94>>, mp_false>)); + + return boost::report_errors(); +} diff --git a/test/mp_and.cpp b/test/mp_and.cpp new file mode 100644 index 0000000..d75552f --- /dev/null +++ b/test/mp_and.cpp @@ -0,0 +1,64 @@ + +// Copyright 2015, 2016 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 + +int main() +{ + using boost::mp_and; + using boost::mp_true; + using boost::mp_false; + using boost::mp_int; + using boost::mp_size_t; + + 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_false>)); + + BOOST_TEST_TRAIT_TRUE((std::is_same>, mp_true>)); + 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_false>)); + + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_true>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_false>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_false>)); + + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_int<5>>, mp_true>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_int<0>>, mp_false>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, void>, mp_false>)); + + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_size_t<8>>, mp_true>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_size_t<0>>, mp_false>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, void>, mp_false>)); + + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_true>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_false>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_false>)); + 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_false>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_false>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_false>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_false>)); + + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_int<2>, mp_int<-11>, mp_int<14>>, mp_true>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_int<0>, void, void>, mp_false>)); + + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_size_t<2>, mp_size_t<114>, mp_size_t<8>, mp_size_t<94>>, mp_true>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_size_t<2>, mp_size_t<0>, void, void>, mp_false>)); + + return boost::report_errors(); +} diff --git a/test/mp_any.cpp b/test/mp_any.cpp new file mode 100644 index 0000000..f7e45c9 --- /dev/null +++ b/test/mp_any.cpp @@ -0,0 +1,62 @@ + +// Copyright 2015, 2016 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 + +int main() +{ + using boost::mp_any; + using boost::mp_true; + using boost::mp_false; + using boost::mp_int; + using boost::mp_size_t; + + 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_false>)); + + BOOST_TEST_TRAIT_TRUE((std::is_same>, mp_true>)); + 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_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>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_false>)); + + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_int<7>>, mp_true>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_size_t<1>>, mp_true>)); + + 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_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_false>)); + + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_int<2>, mp_int<-11>, mp_int<14>>, mp_true>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_int<0>, mp_int<-11>, mp_int<0>>, mp_true>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_int<0>, mp_int<0>, mp_int<0>>, mp_false>)); + + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_size_t<2>, mp_size_t<114>, mp_size_t<8>, mp_size_t<94>>, mp_true>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_size_t<0>, mp_size_t<114>, mp_size_t<0>, mp_size_t<0>>, mp_true>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_size_t<0>, mp_size_t<0>, mp_size_t<0>, mp_size_t<0>>, mp_false>)); + + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_int<0>, mp_false, mp_size_t<141>>, mp_true>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_int<0>, mp_false>, mp_false>)); + + return boost::report_errors(); +} diff --git a/test/mp_map_contains.cpp b/test/mp_map_contains.cpp new file mode 100644 index 0000000..e9d36b2 --- /dev/null +++ b/test/mp_map_contains.cpp @@ -0,0 +1,51 @@ + +// Copyright 2016 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 + +int main() +{ + using boost::mp_map_contains; + using boost::mp_list; + using boost::mp_true; + using boost::mp_false; + + BOOST_TEST_TRAIT_TRUE((std::is_same, char>, mp_false>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, int>, mp_false>)); + + BOOST_TEST_TRAIT_TRUE((std::is_same, std::pair>, char>, mp_false>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, std::pair>, int>, mp_true>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, std::pair>, long>, mp_true>)); + + BOOST_TEST_TRAIT_TRUE((std::is_same, std::pair>, char>, mp_false>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, std::pair>, int>, mp_true>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, std::pair>, long>, mp_true>)); + + BOOST_TEST_TRAIT_TRUE((std::is_same, std::pair>, char>, mp_false>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, std::pair>, int>, mp_true>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, std::pair>, long>, mp_true>)); + + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_list, mp_list>, char>, mp_false>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_list, mp_list>, int>, mp_true>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_list, mp_list>, long>, mp_true>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_list, mp_list>, long long>, mp_true>)); + + BOOST_TEST_TRAIT_TRUE((std::is_same, std::pair, std::tuple>, char>, mp_false>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, std::pair, std::tuple>, int>, mp_true>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, std::pair, std::tuple>, long>, mp_true>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, std::pair, std::tuple>, long long>, mp_true>)); + + return boost::report_errors(); +} diff --git a/test/mp_map_find.cpp b/test/mp_map_find.cpp new file mode 100644 index 0000000..6c26b9b --- /dev/null +++ b/test/mp_map_find.cpp @@ -0,0 +1,48 @@ + +// Copyright 2016 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 + +int main() +{ + using boost::mp_map_find; + using boost::mp_list; + + BOOST_TEST_TRAIT_TRUE((std::is_same, char>, void>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, int>, void>)); + + BOOST_TEST_TRAIT_TRUE((std::is_same, std::pair>, char>, void>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, std::pair>, int>, std::pair>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, std::pair>, long>, std::pair>)); + + BOOST_TEST_TRAIT_TRUE((std::is_same, std::pair>, char>, void>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, std::pair>, int>, std::pair>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, std::pair>, long>, std::pair>)); + + BOOST_TEST_TRAIT_TRUE((std::is_same, std::pair>, char>, void>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, std::pair>, int>, std::pair>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, std::pair>, long>, std::pair>)); + + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_list, mp_list>, char>, void>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_list, mp_list>, int>, mp_list>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_list, mp_list>, long>, mp_list>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_list, mp_list>, long long>, mp_list>)); + + BOOST_TEST_TRAIT_TRUE((std::is_same, std::pair, std::tuple>, char>, void>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, std::pair, std::tuple>, int>, mp_list>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, std::pair, std::tuple>, long>, std::pair>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, std::pair, std::tuple>, long long>, std::tuple>)); + + return boost::report_errors(); +} diff --git a/test/mp_map_insert.cpp b/test/mp_map_insert.cpp new file mode 100644 index 0000000..b334c9f --- /dev/null +++ b/test/mp_map_insert.cpp @@ -0,0 +1,66 @@ + +// Copyright 2016 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 + +int main() +{ + using boost::mp_map_insert; + using boost::mp_list; + using boost::mp_push_back; + + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_list>, mp_list>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, std::tuple>, std::tuple>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, std::pair>, std::tuple>>)); + + { + using M = mp_list, std::pair>; + + BOOST_TEST_TRAIT_TRUE((std::is_same>, mp_push_back>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same>, mp_push_back>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same>, M>)); + BOOST_TEST_TRAIT_TRUE((std::is_same>, M>)); + } + + { + using M = std::tuple, std::pair>; + + BOOST_TEST_TRAIT_TRUE((std::is_same>, mp_push_back>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same>, mp_push_back>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same>, M>)); + BOOST_TEST_TRAIT_TRUE((std::is_same>, M>)); + } + + { + using M = mp_list, mp_list, mp_list>; + + BOOST_TEST_TRAIT_TRUE((std::is_same>, mp_push_back>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same>, mp_push_back>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same>, M>)); + BOOST_TEST_TRAIT_TRUE((std::is_same>, M>)); + BOOST_TEST_TRAIT_TRUE((std::is_same>, M>)); + } + + { + using M = std::tuple, std::pair, std::tuple>; + + BOOST_TEST_TRAIT_TRUE((std::is_same>, mp_push_back>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same>, mp_push_back>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same>, M>)); + BOOST_TEST_TRAIT_TRUE((std::is_same>, M>)); + BOOST_TEST_TRAIT_TRUE((std::is_same>, M>)); + } + + return boost::report_errors(); +} diff --git a/test/mp_map_replace.cpp b/test/mp_map_replace.cpp new file mode 100644 index 0000000..416a0fb --- /dev/null +++ b/test/mp_map_replace.cpp @@ -0,0 +1,66 @@ + +// Copyright 2016 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 + +int main() +{ + using boost::mp_map_replace; + using boost::mp_list; + using boost::mp_push_back; + + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_list>, mp_list>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, std::tuple>, std::tuple>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, std::pair>, std::tuple>>)); + + { + using M = mp_list, std::pair>; + + BOOST_TEST_TRAIT_TRUE((std::is_same>, mp_push_back>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same>, mp_push_back>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same>, mp_list, std::pair>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same>, mp_list, std::pair>>)); + } + + { + using M = std::tuple, std::pair>; + + BOOST_TEST_TRAIT_TRUE((std::is_same>, mp_push_back>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same>, mp_push_back>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same>, std::tuple, std::pair>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same>, std::tuple, std::pair>>)); + } + + { + using M = mp_list, mp_list, mp_list>; + + BOOST_TEST_TRAIT_TRUE((std::is_same>, mp_push_back>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same>, mp_push_back>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same>, mp_list, mp_list, mp_list>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same>, mp_list, std::pair, mp_list>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same>, mp_list, mp_list, mp_list>>)); + } + + { + using M = std::tuple, std::pair, std::tuple>; + + BOOST_TEST_TRAIT_TRUE((std::is_same>, mp_push_back>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same>, mp_push_back>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same>, std::tuple, std::pair, std::tuple>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same>, std::tuple, std::pair, std::tuple>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same>, std::tuple, std::pair, mp_list>>)); + } + + return boost::report_errors(); +} diff --git a/test/mp_or.cpp b/test/mp_or.cpp new file mode 100644 index 0000000..3e4c842 --- /dev/null +++ b/test/mp_or.cpp @@ -0,0 +1,73 @@ + +// Copyright 2015, 2016 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 + +int main() +{ + using boost::mp_or; + using boost::mp_true; + using boost::mp_false; + using boost::mp_int; + using boost::mp_size_t; + + 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_false>)); + + BOOST_TEST_TRAIT_TRUE((std::is_same>, mp_true>)); + 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_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_false>)); + + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_int<0>>, mp_false>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_int<5>>, mp_true>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, void>, mp_true>)); + + BOOST_TEST_TRAIT_TRUE((std::is_same, void>, mp_true>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_size_t<4>>, mp_true>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_size_t<0>>, 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>)); + 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>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_true>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_false>)); + + BOOST_TEST_TRAIT_TRUE((std::is_same, void, void, void>, mp_true>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_int<2>, void, void, void>, mp_true>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_int<0>, mp_int<3>, void, void, void>, mp_true>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_int<0>, mp_int<0>, mp_int<4>, void, void, void>, mp_true>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_int<0>, mp_int<0>, mp_int<0>, mp_int<0>>, mp_false>)); + + BOOST_TEST_TRAIT_TRUE((std::is_same, void, void, void>, mp_true>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_size_t<2>, void, void, void>, mp_true>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_size_t<0>, mp_size_t<3>, void, void, void>, mp_true>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_size_t<0>, mp_size_t<0>, mp_size_t<4>, void, void, void>, mp_true>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_size_t<0>, mp_size_t<0>, mp_size_t<0>, mp_size_t<0>>, mp_false>)); + + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_int<0>, mp_false, mp_size_t<141>, void, void, void>, mp_true>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_int<0>, mp_false>, mp_false>)); + + return boost::report_errors(); +}