From df8217ce9797d0b2729182bbe44e0d8d67bda2d9 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Sun, 22 Oct 2017 02:50:29 +0300 Subject: [PATCH] Add mp_all_of_q, mp_any_of_q, mp_none_of_q --- doc/mp11/algorithm.adoc | 18 ++++++++ include/boost/mp11/algorithm.hpp | 3 ++ test/Jamfile | 3 ++ test/mp_all_of_q.cpp | 59 +++++++++++++++++++++++++ test/mp_any_of_q.cpp | 74 ++++++++++++++++++++++++++++++++ test/mp_none_of_q.cpp | 74 ++++++++++++++++++++++++++++++++ 6 files changed, 231 insertions(+) create mode 100644 test/mp_all_of_q.cpp create mode 100644 test/mp_any_of_q.cpp create mode 100644 test/mp_none_of_q.cpp diff --git a/doc/mp11/algorithm.adoc b/doc/mp11/algorithm.adoc index 8e651e6..372f406 100644 --- a/doc/mp11/algorithm.adoc +++ b/doc/mp11/algorithm.adoc @@ -609,6 +609,12 @@ As `mp_reverse_fold`, but takes a quoted metafunction. `mp_all_of` is `mp_true` when `P` holds for all elements of `L`, `mp_false` otherwise. When `L` is empty, the result is `mp_true`. +## mp_all_of_q + + template using mp_all_of_q = mp_all_of; + +As `mp_all_of`, but takes a quoted metafunction. + ## mp_none_of template class P> using mp_none_of = @@ -616,6 +622,12 @@ As `mp_reverse_fold`, but takes a quoted metafunction. `mp_none_of` is `mp_true` when `P` holds for no element of `L`, `mp_false` otherwise. When `L` is empty, the result is `mp_true`. +## mp_none_of_q + + template using mp_none_of_q = mp_none_of; + +As `mp_none_of`, but takes a quoted metafunction. + ## mp_any_of template class P> using mp_any_of = @@ -623,6 +635,12 @@ As `mp_reverse_fold`, but takes a quoted metafunction. `mp_any_of` is `mp_true` when `P` holds for at least one element of `L`, `mp_false` otherwise. When `L` is empty, the result is `mp_false`. +## mp_any_of_q + + template using mp_any_of_q = mp_any_of; + +As `mp_any_of`, but takes a quoted metafunction. + ## mp_for_each(f) template constexpr F mp_for_each(F&& f); diff --git a/include/boost/mp11/algorithm.hpp b/include/boost/mp11/algorithm.hpp index 9487767..81d6ef9 100644 --- a/include/boost/mp11/algorithm.hpp +++ b/include/boost/mp11/algorithm.hpp @@ -868,12 +868,15 @@ template using mp_unique = typename detail::mp_unique_impl::type; // mp_all_of template class P> using mp_all_of = mp_bool< mp_count_if::value == mp_size::value >; +template using mp_all_of_q = mp_all_of; // mp_none_of template class P> using mp_none_of = mp_bool< mp_count_if::value == 0 >; +template using mp_none_of_q = mp_none_of; // mp_any_of template class P> using mp_any_of = mp_bool< mp_count_if::value != 0 >; +template using mp_any_of_q = mp_any_of; // mp_replace_at_c namespace detail diff --git a/test/Jamfile b/test/Jamfile index 908457f..4ee9ae3 100644 --- a/test/Jamfile +++ b/test/Jamfile @@ -75,8 +75,11 @@ run mp_reverse_fold.cpp ; run mp_reverse_fold_q.cpp ; run mp_unique.cpp ; run mp_all_of.cpp ; +run mp_all_of_q.cpp ; run mp_any_of.cpp ; +run mp_any_of_q.cpp ; run mp_none_of.cpp ; +run mp_none_of_q.cpp ; run mp_replace_at.cpp ; run mp_replace_at_c.cpp ; run mp_for_each.cpp ; diff --git a/test/mp_all_of_q.cpp b/test/mp_all_of_q.cpp new file mode 100644 index 0000000..8a877c5 --- /dev/null +++ b/test/mp_all_of_q.cpp @@ -0,0 +1,59 @@ + +// Copyright 2015, 2016, 2017 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 +#include + +struct X1 {}; + +int main() +{ + using boost::mp11::mp_list; + using boost::mp11::mp_all_of_q; + using boost::mp11::mp_true; + using boost::mp11::mp_false; + using boost::mp11::mp_quote; + + { + 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_q.cpp b/test/mp_any_of_q.cpp new file mode 100644 index 0000000..17b50dc --- /dev/null +++ b/test/mp_any_of_q.cpp @@ -0,0 +1,74 @@ + +// Copyright 2015, 2016, 2017 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 +#include + +struct X1 {}; + +int main() +{ + using boost::mp11::mp_list; + using boost::mp11::mp_any_of_q; + using boost::mp11::mp_true; + using boost::mp11::mp_false; + using boost::mp11::mp_quote; + + { + 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_q.cpp b/test/mp_none_of_q.cpp new file mode 100644 index 0000000..dd4ba63 --- /dev/null +++ b/test/mp_none_of_q.cpp @@ -0,0 +1,74 @@ + +// Copyright 2015, 2016, 2017 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 +#include + +struct X1 {}; + +int main() +{ + using boost::mp11::mp_list; + using boost::mp11::mp_none_of_q; + using boost::mp11::mp_true; + using boost::mp11::mp_false; + using boost::mp11::mp_quote; + + { + 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(); +}