From 72c9c492249c309812bf2b49fd3d2b335067f191 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Thu, 23 Mar 2017 19:22:42 +0200 Subject: [PATCH 1/2] Unroll cx_plus a bit. --- include/boost/mp11/detail/mp_count.hpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/include/boost/mp11/detail/mp_count.hpp b/include/boost/mp11/detail/mp_count.hpp index c03128f..12bde18 100644 --- a/include/boost/mp11/detail/mp_count.hpp +++ b/include/boost/mp11/detail/mp_count.hpp @@ -36,6 +36,12 @@ template constexpr std::size_t cx_plus(T1 t1, T... t) return t1 + cx_plus(t...); } +template +constexpr std::size_t cx_plus(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9, T10 t10, T... t) +{ + return t1 + t2 + t3 + t4 + t5 + t6 + t7 + t8 + t9 + t10 + cx_plus(t...); +} + template class L, class... T, class V> struct mp_count_impl, V> { using type = mp_size_t::value...)>; From 848c2ff82ca81046acc0a8343b7892a7738f0af1 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Thu, 23 Mar 2017 19:34:43 +0200 Subject: [PATCH 2/2] Add fold expr implementations of mp_count, mp_count_if --- include/boost/mp11/detail/mp_count.hpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/include/boost/mp11/detail/mp_count.hpp b/include/boost/mp11/detail/mp_count.hpp index 12bde18..ef97827 100644 --- a/include/boost/mp11/detail/mp_count.hpp +++ b/include/boost/mp11/detail/mp_count.hpp @@ -24,7 +24,14 @@ namespace detail template struct mp_count_impl; -#if !defined( BOOST_MP11_NO_CONSTEXPR ) +#if defined( BOOST_MP11_HAS_FOLD_EXPRESSIONS ) + +template class L, class... T, class V> struct mp_count_impl, V> +{ + using type = mp_size_t<(std::is_same::value + ... + 0)>; +}; + +#elif !defined( BOOST_MP11_NO_CONSTEXPR ) constexpr std::size_t cx_plus() { @@ -66,7 +73,14 @@ namespace detail template class P> struct mp_count_if_impl; -#if !defined( BOOST_MP11_NO_CONSTEXPR ) +#if defined( BOOST_MP11_HAS_FOLD_EXPRESSIONS ) + +template class L, class... T, template class P> struct mp_count_if_impl, P> +{ + using type = mp_size_t<(mp_to_bool>::value + ... + 0)>; +}; + +#elif !defined( BOOST_MP11_NO_CONSTEXPR ) template class L, class... T, template class P> struct mp_count_if_impl, P> {