diff --git a/doc/mp11/algorithm.adoc b/doc/mp11/algorithm.adoc index 8c51983..aa6723e 100644 --- a/doc/mp11/algorithm.adoc +++ b/doc/mp11/algorithm.adoc @@ -187,6 +187,12 @@ using R1 = mp_fill; // std::pair `mp_count_if` returns `mp_size_t`, where `N` is the number of elements `T` of `L` for which `mp_to_bool>` is `mp_true`. +## mp_count_if_q + + template using mp_count_if_q = mp_count_if; + +As `mp_count_if`, but takes a quoted metafunction. + ## mp_contains template using mp_contains = mp_to_bool>; diff --git a/include/boost/mp11/detail/mp_count.hpp b/include/boost/mp11/detail/mp_count.hpp index 962b23f..4ae1144 100644 --- a/include/boost/mp11/detail/mp_count.hpp +++ b/include/boost/mp11/detail/mp_count.hpp @@ -108,6 +108,7 @@ template class L, class... T, template class P> str } // namespace detail template class P> using mp_count_if = typename detail::mp_count_if_impl::type; +template using mp_count_if_q = mp_count_if; } // namespace mp11 } // namespace boost diff --git a/test/Jamfile b/test/Jamfile index 4ce6e88..bebab98 100644 --- a/test/Jamfile +++ b/test/Jamfile @@ -44,6 +44,7 @@ run mp_transform_if_q.cpp ; run mp_fill.cpp ; run mp_count.cpp ; run mp_count_if.cpp ; +run mp_count_if_q.cpp ; run mp_contains.cpp ; run mp_repeat.cpp ; run mp_product.cpp ; diff --git a/test/mp_count_if_q.cpp b/test/mp_count_if_q.cpp new file mode 100644 index 0000000..d76ab4d --- /dev/null +++ b/test/mp_count_if_q.cpp @@ -0,0 +1,61 @@ + +// 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 +#include + +struct X1 {}; + +int main() +{ + using boost::mp11::mp_list; + using boost::mp11::mp_count_if_q; + using boost::mp11::mp_size_t; + using boost::mp11::mp_quote; + + { + using L1 = mp_list<>; + + BOOST_TEST_TRAIT_TRUE((std::is_same>, mp_size_t<0>>)); + + using L2 = mp_list; + + BOOST_TEST_TRAIT_TRUE((std::is_same>, mp_size_t<0>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same>, mp_size_t<2>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same>, mp_size_t<3>>)); + } + + { + using L1 = std::tuple<>; + + BOOST_TEST_TRAIT_TRUE((std::is_same>, mp_size_t<0>>)); + + using L2 = std::tuple; + + BOOST_TEST_TRAIT_TRUE((std::is_same>, mp_size_t<0>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same>, mp_size_t<2>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same>, mp_size_t<3>>)); + } + + { + using L2 = std::pair; + + BOOST_TEST_TRAIT_TRUE((std::is_same>, mp_size_t<0>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same>, mp_size_t<1>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same>, mp_size_t<1>>)); + } + + return boost::report_errors(); +}