diff --git a/doc/mp11/algorithm.adoc b/doc/mp11/algorithm.adoc index 4a44995..240b40d 100644 --- a/doc/mp11/algorithm.adoc +++ b/doc/mp11/algorithm.adoc @@ -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>` is `mp_true` to a new list of the same type and returns it. +## mp_copy_if_q + + template using mp_copy_if_q = mp_copy_if; + +As `mp_copy_if`, but takes a quoted metafunction. + ## mp_remove template using mp_remove = /*...*/; diff --git a/include/boost/mp11/algorithm.hpp b/include/boost/mp11/algorithm.hpp index 44130d2..6c22a39 100644 --- a/include/boost/mp11/algorithm.hpp +++ b/include/boost/mp11/algorithm.hpp @@ -412,6 +412,7 @@ template class L, class... T, template class P> str } // namespace detail template class P> using mp_copy_if = typename detail::mp_copy_if_impl::type; +template using mp_copy_if_q = mp_copy_if; // mp_remove namespace detail diff --git a/test/Jamfile b/test/Jamfile index 9c95adf..2176b09 100644 --- a/test/Jamfile +++ b/test/Jamfile @@ -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 ; diff --git a/test/mp_copy_if_q.cpp b/test/mp_copy_if_q.cpp new file mode 100644 index 0000000..ef75db2 --- /dev/null +++ b/test/mp_copy_if_q.cpp @@ -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 +#include +#include +#include +#include +#include +#include + +struct X1 {}; +struct X2 {}; +struct X3 {}; + +using boost::mp11::mp_bool; + +struct Q_is_even +{ + template using fn = mp_bool; +}; + +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>, L1>)); + + using L2 = mp_list; + + BOOST_TEST_TRAIT_TRUE((std::is_same>, L1>)); + BOOST_TEST_TRAIT_TRUE((std::is_same>, mp_list>)); + BOOST_TEST_TRAIT_TRUE((std::is_same>, mp_list>)); + } + + { + using L1 = std::tuple<>; + + BOOST_TEST_TRAIT_TRUE((std::is_same>, L1>)); + + using L2 = std::tuple; + + BOOST_TEST_TRAIT_TRUE((std::is_same>, L1>)); + BOOST_TEST_TRAIT_TRUE((std::is_same>, std::tuple>)); + BOOST_TEST_TRAIT_TRUE((std::is_same>, std::tuple>)); + } + + using boost::mp11::mp_iota_c; + using boost::mp11::mp_size_t; + + { + int const N = 12; + using L1 = mp_iota_c; + + using R1 = mp_copy_if_q; + + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_size_t<2>, mp_size_t<4>, mp_size_t<6>, mp_size_t<8>, mp_size_t<10>>>)); + } + + return boost::report_errors(); +}