forked from boostorg/mp11
Add mp_all_of_q, mp_any_of_q, mp_none_of_q
This commit is contained in:
@ -609,6 +609,12 @@ As `mp_reverse_fold`, but takes a quoted metafunction.
|
||||
|
||||
`mp_all_of<L, P>` 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<L, Q>
|
||||
|
||||
template<class L, class Q> using mp_all_of_q = mp_all_of<L, Q::template fn>;
|
||||
|
||||
As `mp_all_of`, but takes a quoted metafunction.
|
||||
|
||||
## mp_none_of<L, P>
|
||||
|
||||
template<class L, template<class...> class P> using mp_none_of =
|
||||
@ -616,6 +622,12 @@ As `mp_reverse_fold`, but takes a quoted metafunction.
|
||||
|
||||
`mp_none_of<L, P>` 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<L, Q>
|
||||
|
||||
template<class L, class Q> using mp_none_of_q = mp_none_of<L, Q::template fn>;
|
||||
|
||||
As `mp_none_of`, but takes a quoted metafunction.
|
||||
|
||||
## mp_any_of<L, P>
|
||||
|
||||
template<class L, template<class...> class P> using mp_any_of =
|
||||
@ -623,6 +635,12 @@ As `mp_reverse_fold`, but takes a quoted metafunction.
|
||||
|
||||
`mp_any_of<L, P>` 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<L, Q>
|
||||
|
||||
template<class L, class Q> using mp_any_of_q = mp_any_of<L, Q::template fn>;
|
||||
|
||||
As `mp_any_of`, but takes a quoted metafunction.
|
||||
|
||||
## mp_for_each<L>(f)
|
||||
|
||||
template<class L, class F> constexpr F mp_for_each(F&& f);
|
||||
|
@ -868,12 +868,15 @@ template<class L> using mp_unique = typename detail::mp_unique_impl<L>::type;
|
||||
|
||||
// mp_all_of<L, P>
|
||||
template<class L, template<class...> class P> using mp_all_of = mp_bool< mp_count_if<L, P>::value == mp_size<L>::value >;
|
||||
template<class L, class Q> using mp_all_of_q = mp_all_of<L, Q::template fn>;
|
||||
|
||||
// mp_none_of<L, P>
|
||||
template<class L, template<class...> class P> using mp_none_of = mp_bool< mp_count_if<L, P>::value == 0 >;
|
||||
template<class L, class Q> using mp_none_of_q = mp_none_of<L, Q::template fn>;
|
||||
|
||||
// mp_any_of<L, P>
|
||||
template<class L, template<class...> class P> using mp_any_of = mp_bool< mp_count_if<L, P>::value != 0 >;
|
||||
template<class L, class Q> using mp_any_of_q = mp_any_of<L, Q::template fn>;
|
||||
|
||||
// mp_replace_at_c<L, I, W>
|
||||
namespace detail
|
||||
|
@ -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 ;
|
||||
|
59
test/mp_all_of_q.cpp
Normal file
59
test/mp_all_of_q.cpp
Normal file
@ -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 <boost/mp11/algorithm.hpp>
|
||||
#include <boost/mp11/list.hpp>
|
||||
#include <boost/mp11/integral.hpp>
|
||||
#include <boost/mp11/utility.hpp>
|
||||
#include <boost/core/lightweight_test_trait.hpp>
|
||||
#include <type_traits>
|
||||
#include <tuple>
|
||||
#include <utility>
|
||||
|
||||
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_all_of_q<L1, mp_quote<std::is_const>>, mp_true>));
|
||||
|
||||
using L2 = mp_list<X1 const, X1 const, X1 const volatile, X1 const, X1 const volatile>;
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_all_of_q<L2, mp_quote<std::is_volatile>>, mp_false>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_all_of_q<L2, mp_quote<std::is_const>>, mp_true>));
|
||||
}
|
||||
|
||||
{
|
||||
using L1 = std::tuple<>;
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_all_of_q<L1, mp_quote<std::is_const>>, mp_true>));
|
||||
|
||||
using L2 = std::tuple<X1 const, X1 const, X1 const volatile, X1 const, X1 const volatile>;
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_all_of_q<L2, mp_quote<std::is_volatile>>, mp_false>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_all_of_q<L2, mp_quote<std::is_const>>, mp_true>));
|
||||
}
|
||||
|
||||
{
|
||||
using L2 = std::pair<X1 const, X1 const volatile>;
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_all_of_q<L2, mp_quote<std::is_volatile>>, mp_false>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_all_of_q<L2, mp_quote<std::is_const>>, mp_true>));
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
74
test/mp_any_of_q.cpp
Normal file
74
test/mp_any_of_q.cpp
Normal file
@ -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 <boost/mp11/algorithm.hpp>
|
||||
#include <boost/mp11/list.hpp>
|
||||
#include <boost/mp11/integral.hpp>
|
||||
#include <boost/mp11/utility.hpp>
|
||||
#include <boost/core/lightweight_test_trait.hpp>
|
||||
#include <type_traits>
|
||||
#include <tuple>
|
||||
#include <utility>
|
||||
|
||||
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_any_of_q<L1, mp_quote<std::is_const>>, mp_false>));
|
||||
|
||||
using L2 = mp_list<X1, X1 const, X1, X1, X1>;
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_any_of_q<L2, mp_quote<std::is_volatile>>, mp_false>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_any_of_q<L2, mp_quote<std::is_const>>, mp_true>));
|
||||
|
||||
using L3 = mp_list<X1 const, X1 const, X1, X1 const, X1>;
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_any_of_q<L3, mp_quote<std::is_volatile>>, mp_false>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_any_of_q<L3, mp_quote<std::is_const>>, mp_true>));
|
||||
}
|
||||
|
||||
{
|
||||
using L1 = std::tuple<>;
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_any_of_q<L1, mp_quote<std::is_const>>, mp_false>));
|
||||
|
||||
using L2 = std::tuple<X1, X1 const, X1, X1, X1>;
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_any_of_q<L2, mp_quote<std::is_volatile>>, mp_false>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_any_of_q<L2, mp_quote<std::is_const>>, mp_true>));
|
||||
|
||||
using L3 = std::tuple<X1 const, X1 const, X1, X1 const, X1>;
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_any_of_q<L3, mp_quote<std::is_volatile>>, mp_false>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_any_of_q<L3, mp_quote<std::is_const>>, mp_true>));
|
||||
}
|
||||
|
||||
{
|
||||
using L2 = std::pair<X1 const, X1>;
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_any_of_q<L2, mp_quote<std::is_volatile>>, mp_false>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_any_of_q<L2, mp_quote<std::is_const>>, mp_true>));
|
||||
|
||||
using L3 = std::pair<X1 const, X1 const>;
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_any_of_q<L3, mp_quote<std::is_volatile>>, mp_false>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_any_of_q<L3, mp_quote<std::is_const>>, mp_true>));
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
74
test/mp_none_of_q.cpp
Normal file
74
test/mp_none_of_q.cpp
Normal file
@ -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 <boost/mp11/algorithm.hpp>
|
||||
#include <boost/mp11/list.hpp>
|
||||
#include <boost/mp11/integral.hpp>
|
||||
#include <boost/mp11/utility.hpp>
|
||||
#include <boost/core/lightweight_test_trait.hpp>
|
||||
#include <type_traits>
|
||||
#include <tuple>
|
||||
#include <utility>
|
||||
|
||||
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_none_of_q<L1, mp_quote<std::is_const>>, mp_true>));
|
||||
|
||||
using L2 = mp_list<X1, X1 const, X1, X1, X1>;
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_none_of_q<L2, mp_quote<std::is_volatile>>, mp_true>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_none_of_q<L2, mp_quote<std::is_const>>, mp_false>));
|
||||
|
||||
using L3 = mp_list<X1 const, X1 const, X1, X1 const, X1>;
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_none_of_q<L3, mp_quote<std::is_volatile>>, mp_true>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_none_of_q<L3, mp_quote<std::is_const>>, mp_false>));
|
||||
}
|
||||
|
||||
{
|
||||
using L1 = std::tuple<>;
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_none_of_q<L1, mp_quote<std::is_const>>, mp_true>));
|
||||
|
||||
using L2 = std::tuple<X1, X1 const, X1, X1, X1>;
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_none_of_q<L2, mp_quote<std::is_volatile>>, mp_true>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_none_of_q<L2, mp_quote<std::is_const>>, mp_false>));
|
||||
|
||||
using L3 = std::tuple<X1 const, X1 const, X1, X1 const, X1>;
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_none_of_q<L3, mp_quote<std::is_volatile>>, mp_true>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_none_of_q<L3, mp_quote<std::is_const>>, mp_false>));
|
||||
}
|
||||
|
||||
{
|
||||
using L2 = std::pair<X1 const, X1>;
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_none_of_q<L2, mp_quote<std::is_volatile>>, mp_true>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_none_of_q<L2, mp_quote<std::is_const>>, mp_false>));
|
||||
|
||||
using L3 = std::pair<X1 const, X1 const>;
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_none_of_q<L3, mp_quote<std::is_volatile>>, mp_true>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_none_of_q<L3, mp_quote<std::is_const>>, mp_false>));
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
Reference in New Issue
Block a user