diff --git a/include/boost/mp11/algorithm.hpp b/include/boost/mp11/algorithm.hpp index 581a213..5b04a17 100644 --- a/include/boost/mp11/algorithm.hpp +++ b/include/boost/mp11/algorithm.hpp @@ -970,11 +970,34 @@ template BOOST_MP11_CONSTEXPR F mp_for_each_impl( mp_list<>, F && f ) } // namespace detail +#if BOOST_MP11_WORKAROUND( BOOST_MP11_MSVC, >= 1900 ) + +// msvc has a limit of 1024 + +template BOOST_MP11_CONSTEXPR mp_if_c::value <= 1024, F> mp_for_each( F && f ) +{ + return detail::mp_for_each_impl( mp_rename(), std::forward(f) ); +} + +template BOOST_MP11_CONSTEXPR mp_if_c::value >= 1025, F> mp_for_each( F && f ) +{ + using L2 = mp_rename; + + using L3 = mp_take_c; + using L4 = mp_drop_c; + + return mp_for_each( mp_for_each( std::forward(f) ) ); +} + +#else + template BOOST_MP11_CONSTEXPR F mp_for_each( F && f ) { return detail::mp_for_each_impl( mp_rename(), std::forward(f) ); } +#endif + // mp_insert template using mp_insert = mp_append, mp_push_front, T...>>; diff --git a/test/mp_for_each.cpp b/test/mp_for_each.cpp index 72854a7..d38bee5 100644 --- a/test/mp_for_each.cpp +++ b/test/mp_for_each.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #if defined( BOOST_MP11_HAS_CXX14_CONSTEXPR ) # define CONSTEXPR14 constexpr @@ -30,8 +31,8 @@ struct F struct G { - std::size_t s; - CONSTEXPR14 void operator()( std::size_t i ) { s += i; } + std::uint32_t s; + CONSTEXPR14 void operator()( std::uint32_t i ) { s = s * 3 + i; } }; using boost::mp11::mp_list; @@ -55,8 +56,8 @@ int main() #if BOOST_MP11_WORKAROUND( BOOST_MP11_MSVC, <= 1800 ) #else - using L = mp_iota_c<1024>; - std::size_t const R = 523776; + using L = mp_iota_c<1089>; + std::uint32_t const R = 598075296; BOOST_TEST_EQ( (mp_for_each( G{0} ).s), R );