forked from boostorg/mp11
Add mp_copy_if_q
This commit is contained in:
@ -421,6 +421,12 @@ Same as `mp_replace_at_c`, but with a type argument `I`. `I::value` must be a no
|
||||
|
||||
Copies the elements `T` of `L` for which `mp_to_bool<P<T>>` is `mp_true` to a new list of the same type and returns it.
|
||||
|
||||
## mp_copy_if_q<L, Q>
|
||||
|
||||
template<class L, class Q> using mp_copy_if_q = mp_copy_if<L, Q::template fn>;
|
||||
|
||||
As `mp_copy_if`, but takes a quoted metafunction.
|
||||
|
||||
## mp_remove<L, V>
|
||||
|
||||
template<class L, class V> using mp_remove = /*...*/;
|
||||
|
@ -412,6 +412,7 @@ template<template<class...> class L, class... T, template<class...> class P> str
|
||||
} // namespace detail
|
||||
|
||||
template<class L, template<class...> class P> using mp_copy_if = typename detail::mp_copy_if_impl<L, P>::type;
|
||||
template<class L, class Q> using mp_copy_if_q = mp_copy_if<L, Q::template fn>;
|
||||
|
||||
// mp_remove<L, V>
|
||||
namespace detail
|
||||
|
@ -57,6 +57,7 @@ run mp_replace.cpp ;
|
||||
run mp_replace_if.cpp ;
|
||||
run mp_replace_if_q.cpp ;
|
||||
run mp_copy_if.cpp ;
|
||||
run mp_copy_if_q.cpp ;
|
||||
run mp_remove.cpp ;
|
||||
run mp_remove_if.cpp ;
|
||||
run mp_partition.cpp ;
|
||||
|
72
test/mp_copy_if_q.cpp
Normal file
72
test/mp_copy_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_even
|
||||
{
|
||||
template<class N> using fn = mp_bool<N::value % 2 == 0>;
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
using boost::mp11::mp_list;
|
||||
using boost::mp11::mp_copy_if_q;
|
||||
using boost::mp11::mp_quote;
|
||||
|
||||
{
|
||||
using L1 = mp_list<>;
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_copy_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_copy_if_q<L2, mp_quote<std::is_volatile>>, L1>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_copy_if_q<L2, mp_quote<std::is_const>>, mp_list<X1 const, X2 const>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_copy_if_q<L2, mp_quote<std::is_pointer>>, mp_list<X1*, X2*, X3*>>));
|
||||
}
|
||||
|
||||
{
|
||||
using L1 = std::tuple<>;
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_copy_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_copy_if_q<L2, mp_quote<std::is_volatile>>, L1>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_copy_if_q<L2, mp_quote<std::is_const>>, std::tuple<X1 const, X2 const>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_copy_if_q<L2, mp_quote<std::is_pointer>>, std::tuple<X1*, X2*, X3*>>));
|
||||
}
|
||||
|
||||
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_copy_if_q<L1, Q_is_even>;
|
||||
|
||||
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