From c92d2d0b6fa9ae77094416f8142a8128c0424941 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Mon, 22 Mar 2021 19:17:44 +0200 Subject: [PATCH] No longer use fold expressions for mp_count_if to avoid compiler limits --- 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 09cb0f6..bc8aed9 100644 --- a/include/boost/mp11/detail/mp_count.hpp +++ b/include/boost/mp11/detail/mp_count.hpp @@ -90,11 +90,25 @@ namespace detail template class P> struct mp_count_if_impl; -#if defined( BOOST_MP11_HAS_FOLD_EXPRESSIONS ) && !BOOST_MP11_WORKAROUND( BOOST_MP11_MSVC, < 1930 ) +#if defined( BOOST_MP11_HAS_CXX14_CONSTEXPR ) && !BOOST_MP11_WORKAROUND( BOOST_MP11_MSVC, < 1930 ) + +template class P, class... T> constexpr std::size_t cx_count_if() +{ + constexpr bool a[] = { false, static_cast( P::value )... }; + + std::size_t r = 0; + + for( std::size_t i = 0; i < sizeof...(T); ++i ) + { + r += a[ i+1 ]; + } + + return r; +} template class L, class... T, template class P> struct mp_count_if_impl, P> { - using type = mp_size_t<(mp_to_bool>::value + ... + 0)>; + using type = mp_size_t()>; }; #elif !defined( BOOST_MP11_NO_CONSTEXPR )