From dad038eea17d0d2dab7f10c0f821a2b4a2a1fd98 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Sun, 23 Jul 2017 16:21:41 +0300 Subject: [PATCH] Use C++14 constexpr in cx_find_index as it's much less taxing for large N --- include/boost/mp11/algorithm.hpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/include/boost/mp11/algorithm.hpp b/include/boost/mp11/algorithm.hpp index dbd3ef5..4dce8c4 100644 --- a/include/boost/mp11/algorithm.hpp +++ b/include/boost/mp11/algorithm.hpp @@ -576,11 +576,30 @@ template class L, class V> struct mp_find_impl, V> using type = mp_size_t<0>; }; +#if !defined( BOOST_NO_CXX14_CONSTEXPR ) + +constexpr std::size_t cx_find_index( bool const * first, bool const * last ) +{ + std::size_t m = 0; + + while( first != last && !*first ) + { + ++m; + ++first; + } + + return m; +} + +#else + constexpr std::size_t cx_find_index( bool const * first, bool const * last ) { return first == last || *first? 0: 1 + cx_find_index( first + 1, last ); } +#endif + template class L, class... T, class V> struct mp_find_impl, V> { static constexpr bool _v[] = { std::is_same::value... };