forked from boostorg/mp11
Add mp_remove_if_q
This commit is contained in:
@ -439,6 +439,12 @@ Removes all `V` elements of `L` and returns the result.
|
||||
|
||||
Removes all elements `T` of `L` for which `mp_to_bool<P<T>>` is `mp_true` and returns the result.
|
||||
|
||||
## mp_remove_if_q<L, Q>
|
||||
|
||||
template<class L, class Q> using mp_remove_if_q = mp_remove_if<L, Q::template fn>;
|
||||
|
||||
As `mp_remove_if`, but takes a quoted metafunction.
|
||||
|
||||
## mp_partition<L, P>
|
||||
|
||||
template<class L, template<class...> class P> using mp_partition = /*...*/;
|
||||
|
@ -455,6 +455,7 @@ template<template<class...> class L, class... T, template<class...> class P> str
|
||||
} // namespace detail
|
||||
|
||||
template<class L, template<class...> class P> using mp_remove_if = typename detail::mp_remove_if_impl<L, P>::type;
|
||||
template<class L, class Q> using mp_remove_if_q = mp_remove_if<L, Q::template fn>;
|
||||
|
||||
// mp_partition<L, P>
|
||||
namespace detail
|
||||
|
@ -60,6 +60,7 @@ run mp_copy_if.cpp ;
|
||||
run mp_copy_if_q.cpp ;
|
||||
run mp_remove.cpp ;
|
||||
run mp_remove_if.cpp ;
|
||||
run mp_remove_if_q.cpp ;
|
||||
run mp_partition.cpp ;
|
||||
run mp_sort.cpp ;
|
||||
run mp_find.cpp ;
|
||||
|
@ -51,10 +51,10 @@ int main()
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_remove_if<L2, std::is_pointer>, std::tuple<X1, X1 const, X2 const>>));
|
||||
}
|
||||
|
||||
using boost::mp11::mp_iota_c;
|
||||
using boost::mp11::mp_size_t;
|
||||
using boost::mp11::mp_iota_c;
|
||||
using boost::mp11::mp_size_t;
|
||||
|
||||
{
|
||||
{
|
||||
int const N = 12;
|
||||
using L1 = mp_iota_c<N>;
|
||||
|
||||
|
72
test/mp_remove_if_q.cpp
Normal file
72
test/mp_remove_if_q.cpp
Normal file
@ -0,0 +1,72 @@
|
||||
|
||||
// Copyright 2015-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>
|
||||
|
||||
struct X1 {};
|
||||
struct X2 {};
|
||||
struct X3 {};
|
||||
|
||||
using boost::mp11::mp_bool;
|
||||
|
||||
struct Q_is_odd
|
||||
{
|
||||
template<class N> using fn = mp_bool<N::value % 2 != 0>;
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
using boost::mp11::mp_list;
|
||||
using boost::mp11::mp_remove_if_q;
|
||||
using boost::mp11::mp_quote;
|
||||
|
||||
{
|
||||
using L1 = mp_list<>;
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_remove_if_q<L1, mp_quote<std::is_const>>, L1>));
|
||||
|
||||
using L2 = mp_list<X1, X1 const, X1*, X2 const, X2*, X3*>;
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_remove_if_q<L2, mp_quote<std::is_volatile>>, L2>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_remove_if_q<L2, mp_quote<std::is_const>>, mp_list<X1, X1*, X2*, X3*>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_remove_if_q<L2, mp_quote<std::is_pointer>>, mp_list<X1, X1 const, X2 const>>));
|
||||
}
|
||||
|
||||
{
|
||||
using L1 = std::tuple<>;
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_remove_if_q<L1, mp_quote<std::is_const>>, L1>));
|
||||
|
||||
using L2 = std::tuple<X1, X1 const, X1*, X2 const, X2*, X3*>;
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_remove_if_q<L2, mp_quote<std::is_volatile>>, L2>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_remove_if_q<L2, mp_quote<std::is_const>>, std::tuple<X1, X1*, X2*, X3*>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_remove_if_q<L2, mp_quote<std::is_pointer>>, std::tuple<X1, X1 const, X2 const>>));
|
||||
}
|
||||
|
||||
using boost::mp11::mp_iota_c;
|
||||
using boost::mp11::mp_size_t;
|
||||
|
||||
{
|
||||
int const N = 12;
|
||||
using L1 = mp_iota_c<N>;
|
||||
|
||||
using R1 = mp_remove_if_q<L1, Q_is_odd>;
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<R1, mp_list<mp_size_t<0>, mp_size_t<2>, mp_size_t<4>, mp_size_t<6>, mp_size_t<8>, mp_size_t<10>>>));
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
Reference in New Issue
Block a user