From 29d030ac592f0b5027ab58c65db5549e6e49bdf1 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Wed, 16 Nov 2016 04:19:37 +0200 Subject: [PATCH] Add mp_all_of, mp_any_of, mp_none_of. --- include/boost/mp11/algorithm.hpp | 7 +++- include/boost/mp11/function.hpp | 9 +++- test/Jamfile.v2 | 3 ++ test/mp_all_of.cpp | 57 +++++++++++++++++++++++++ test/mp_any_of.cpp | 72 ++++++++++++++++++++++++++++++++ test/mp_none_of.cpp | 72 ++++++++++++++++++++++++++++++++ 6 files changed, 218 insertions(+), 2 deletions(-) create mode 100644 test/mp_all_of.cpp create mode 100644 test/mp_any_of.cpp create mode 100644 test/mp_none_of.cpp diff --git a/include/boost/mp11/algorithm.hpp b/include/boost/mp11/algorithm.hpp index 7c601b4..76f727e 100644 --- a/include/boost/mp11/algorithm.hpp +++ b/include/boost/mp11/algorithm.hpp @@ -12,7 +12,7 @@ #include #include #include -#include +#include #include #include #include @@ -796,8 +796,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 >; + // mp_none_of +template class P> using mp_none_of = mp_not< mp_count_if >; + // mp_any_of +template class P> using mp_any_of = mp_to_bool< mp_count_if >; } // namespace boost diff --git a/include/boost/mp11/function.hpp b/include/boost/mp11/function.hpp index 68d1494..c78fe29 100644 --- a/include/boost/mp11/function.hpp +++ b/include/boost/mp11/function.hpp @@ -8,11 +8,18 @@ // See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt +#include +#include + namespace boost { -// mp_plus // 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 // mp_and // mp_any diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 76efec9..1457fdf 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -55,6 +55,9 @@ run mp_reverse.cpp : : : $(REQ) ; run mp_fold.cpp : : : $(REQ) ; run mp_reverse_fold.cpp : : : $(REQ) ; run mp_unique.cpp : : : $(REQ) ; +run mp_all_of.cpp : : : $(REQ) ; +run mp_any_of.cpp : : : $(REQ) ; +run mp_none_of.cpp : : : $(REQ) ; # integral run integral.cpp : : : $(REQ) ; diff --git a/test/mp_all_of.cpp b/test/mp_all_of.cpp new file mode 100644 index 0000000..a19b18e --- /dev/null +++ b/test/mp_all_of.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 +#include +#include +#include + +struct X1 {}; + +int main() +{ + using boost::mp_list; + using boost::mp_all_of; + using boost::mp_true; + using boost::mp_false; + + { + using L1 = mp_list<>; + + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_true>)); + + using L2 = mp_list; + + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_false>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_true>)); + } + + { + using L1 = std::tuple<>; + + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_true>)); + + using L2 = std::tuple; + + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_false>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_true>)); + } + + { + using L2 = std::pair; + + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_false>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_true>)); + } + + return boost::report_errors(); +} diff --git a/test/mp_any_of.cpp b/test/mp_any_of.cpp new file mode 100644 index 0000000..bcf3c19 --- /dev/null +++ b/test/mp_any_of.cpp @@ -0,0 +1,72 @@ + +// 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 +#include + +struct X1 {}; + +int main() +{ + using boost::mp_list; + using boost::mp_any_of; + 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>)); + + using L3 = mp_list; + + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_false>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_true>)); + } + + { + using L1 = std::tuple<>; + + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_false>)); + + using L2 = std::tuple; + + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_false>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_true>)); + + using L3 = std::tuple; + + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_false>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_true>)); + } + + { + using L2 = std::pair; + + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_false>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_true>)); + + using L3 = std::pair; + + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_false>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_true>)); + } + + return boost::report_errors(); +} diff --git a/test/mp_none_of.cpp b/test/mp_none_of.cpp new file mode 100644 index 0000000..1ee4099 --- /dev/null +++ b/test/mp_none_of.cpp @@ -0,0 +1,72 @@ + +// 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 +#include + +struct X1 {}; + +int main() +{ + using boost::mp_list; + using boost::mp_none_of; + using boost::mp_true; + using boost::mp_false; + + { + using L1 = mp_list<>; + + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_true>)); + + using L2 = mp_list; + + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_true>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_false>)); + + using L3 = mp_list; + + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_true>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_false>)); + } + + { + using L1 = std::tuple<>; + + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_true>)); + + using L2 = std::tuple; + + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_true>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_false>)); + + using L3 = std::tuple; + + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_true>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_false>)); + } + + { + using L2 = std::pair; + + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_true>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_false>)); + + using L3 = std::pair; + + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_true>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_false>)); + } + + return boost::report_errors(); +}