diff --git a/include/boost/algorithm/cxx11/one_of.hpp b/include/boost/algorithm/cxx11/one_of.hpp index f4e2b38..3b95180 100644 --- a/include/boost/algorithm/cxx11/one_of.hpp +++ b/include/boost/algorithm/cxx11/one_of.hpp @@ -12,7 +12,6 @@ #ifndef BOOST_ALGORITHM_ONE_OF_HPP #define BOOST_ALGORITHM_ONE_OF_HPP -#include // for std::find and std::find_if #include #include @@ -30,10 +29,14 @@ namespace boost { namespace algorithm { template BOOST_CXX14_CONSTEXPR bool one_of ( InputIterator first, InputIterator last, Predicate p ) { - InputIterator i = std::find_if (first, last, p); - if (i == last) +// find_if + for (; first != last; ++first) + if (p(*first)) + break; + + if (first == last) return false; // Didn't occur at all - return boost::algorithm::none_of (++i, last, p); + return boost::algorithm::none_of (++first, last, p); } /// \fn one_of ( const Range &r, Predicate p ) @@ -43,7 +46,7 @@ BOOST_CXX14_CONSTEXPR bool one_of ( InputIterator first, InputIterator last, Pre /// \param p A predicate for testing the elements of the range /// template -BOOST_CXX14_CONSTEXPR bool one_of ( const Range &r, Predicate p ) +BOOST_CXX14_CONSTEXPR bool one_of ( const Range &r, Predicate p ) { return boost::algorithm::one_of ( boost::begin (r), boost::end (r), p ); } @@ -57,12 +60,16 @@ BOOST_CXX14_CONSTEXPR bool one_of ( const Range &r, Predicate p ) /// \param val A value to compare against /// template -bool one_of_equal ( InputIterator first, InputIterator last, const V &val ) +BOOST_CXX14_CONSTEXPR bool one_of_equal ( InputIterator first, InputIterator last, const V &val ) { - InputIterator i = std::find (first, last, val); // find first occurrence of 'val' - if (i == last) +// find + for (; first != last; ++first) + if (*first == val) + break; + + if (first == last) return false; // Didn't occur at all - return boost::algorithm::none_of_equal (++i, last, val); + return boost::algorithm::none_of_equal (++first, last, val); } /// \fn one_of_equal ( const Range &r, const V &val ) @@ -72,7 +79,7 @@ bool one_of_equal ( InputIterator first, InputIterator last, const V &val ) /// \param val A value to compare against /// template -bool one_of_equal ( const Range &r, const V &val ) +BOOST_CXX14_CONSTEXPR bool one_of_equal ( const Range &r, const V &val ) { return boost::algorithm::one_of_equal ( boost::begin (r), boost::end (r), val ); } diff --git a/include/boost/algorithm/cxx14/equal.hpp b/include/boost/algorithm/cxx14/equal.hpp index 857435b..526aae9 100644 --- a/include/boost/algorithm/cxx14/equal.hpp +++ b/include/boost/algorithm/cxx14/equal.hpp @@ -12,16 +12,8 @@ #ifndef BOOST_ALGORITHM_EQUAL_HPP #define BOOST_ALGORITHM_EQUAL_HPP -#include // for std::equal #include -#ifdef __cpp_lib_array_constexpr // or cpp17 compiler -// if compiled according to C++17 standard or std functions are constexpr -#define BOOST_CONSTEXPR_IF_STD_CONSTEXPR constexpr -#else -#define BOOST_CONSTEXPR_IF_STD_CONSTEXPR -#endif - namespace boost { namespace algorithm { namespace detail { @@ -32,7 +24,7 @@ namespace detail { }; template - BOOST_CONSTEXPR_IF_STD_CONSTEXPR + BOOST_CXX14_CONSTEXPR bool equal ( RandomAccessIterator1 first1, RandomAccessIterator1 last1, RandomAccessIterator2 first2, RandomAccessIterator2 last2, BinaryPredicate pred, std::random_access_iterator_tag, std::random_access_iterator_tag ) @@ -40,12 +32,16 @@ namespace detail { // Random-access iterators let is check the sizes in constant time if ( std::distance ( first1, last1 ) != std::distance ( first2, last2 )) return false; - // If we know that the sequences are the same size, the original version is fine - return std::equal ( first1, last1, first2, pred ); + + // std::equal + for (; first1 != last1; ++first1, ++first2) + if (!pred(*first1, *first2)) + return false; + return true; } template - BOOST_CXX14_CONSTEXPR + BOOST_CXX14_CONSTEXPR bool equal ( InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, BinaryPredicate pred, std::input_iterator_tag, std::input_iterator_tag ) diff --git a/test/all_of_test.cpp b/test/all_of_test.cpp index a720b0c..a6fdfd6 100644 --- a/test/all_of_test.cpp +++ b/test/all_of_test.cpp @@ -77,12 +77,13 @@ void test_all () BOOST_CHECK ( ba::all_of_equal ( li.begin(), l_iter, 1 )); BOOST_CHECK ( ba::all_of ( li.begin(), l_iter, is_ ( 1 ))); - BOOST_CXX14_CONSTEXPR bool constexpr_res = ( - !ba::all_of_equal ( some_numbers, 1 ) - && !ba::all_of ( some_numbers, is_ ( 1 )) - && ba::all_of_equal ( some_numbers, some_numbers + 3, 1 ) - && ba::all_of ( some_numbers, some_numbers + 3, is_ ( 1 )) - ); + BOOST_CXX14_CONSTEXPR bool constexpr_res = + !ba::all_of_equal ( some_numbers, 1 ) && + !ba::all_of ( some_numbers, is_ ( 1 )) && + ba::all_of_equal ( some_numbers, some_numbers + 3, 1 ) && + ba::all_of ( some_numbers, some_numbers + 3, is_ ( 1 )) && + true; + BOOST_CHECK ( constexpr_res ); } diff --git a/test/any_of_test.cpp b/test/any_of_test.cpp index 193356c..288c0cc 100644 --- a/test/any_of_test.cpp +++ b/test/any_of_test.cpp @@ -97,13 +97,13 @@ void test_any () BOOST_CHECK (!ba::any_of_equal ( li.begin(), l_iter, 18 )); BOOST_CHECK (!ba::any_of ( li.begin(), l_iter, is_ ( 18 ))); - - BOOST_CXX14_CONSTEXPR bool constexpr_res = ( - ba::any_of_equal ( some_numbers, 1 ) - && ba::any_of ( some_numbers, is_ ( 1 )) - && !ba::any_of_equal ( some_numbers, some_numbers + 3, 777 ) - && !ba::any_of ( some_numbers, some_numbers + 3, is_ ( 777 )) - ); + BOOST_CXX14_CONSTEXPR bool constexpr_res = + ba::any_of_equal ( some_numbers, 1 ) && + ba::any_of ( some_numbers, is_ ( 1 )) && + !ba::any_of_equal ( some_numbers, some_numbers + 3, 777 ) && + !ba::any_of ( some_numbers, some_numbers + 3, is_ ( 777 )) && + true; + BOOST_CHECK ( constexpr_res ); } diff --git a/test/clamp_test.cpp b/test/clamp_test.cpp index c3e9433..a6e73b5 100644 --- a/test/clamp_test.cpp +++ b/test/clamp_test.cpp @@ -306,7 +306,7 @@ void test_constexpr() BOOST_CHECK(check_max_out); } { - short foo = 50; + BOOST_CXX14_CONSTEXPR short foo = 50; BOOST_CXX14_CONSTEXPR bool check_float = ( 56 == ba::clamp ( foo, 56.9, 129 )); BOOST_CHECK(check_float); BOOST_CXX14_CONSTEXPR bool check_over = ( 24910 == ba::clamp ( foo, 12345678, 123456999 )); diff --git a/test/none_of_test.cpp b/test/none_of_test.cpp index 9522175..0a20ff4 100644 --- a/test/none_of_test.cpp +++ b/test/none_of_test.cpp @@ -88,13 +88,14 @@ void test_none() BOOST_CHECK ( ba::none_of_equal ( li.begin(), l_iter, 18 )); BOOST_CHECK ( ba::none_of ( li.begin(), l_iter, is_ ( 18 ))); BOOST_CHECK (!ba::none_of ( li.begin(), l_iter, is_ ( 5 ))); - - BOOST_CXX14_CONSTEXPR bool constexpr_res = ( - !ba::none_of_equal ( some_numbers, 1 ) - && !ba::none_of ( some_numbers, is_ ( 1 )) - && ba::none_of_equal ( some_numbers, some_numbers + 3, 100 ) - && ba::none_of ( some_numbers, some_numbers + 3, is_ ( 100 )) - ); + + BOOST_CXX14_CONSTEXPR bool constexpr_res = + !ba::none_of_equal ( some_numbers, 1 ) && + !ba::none_of ( some_numbers, is_ ( 1 )) && + ba::none_of_equal ( some_numbers, some_numbers + 3, 100 ) && + ba::none_of ( some_numbers, some_numbers + 3, is_ ( 100 )) && + true; + BOOST_CHECK ( constexpr_res ); } diff --git a/test/one_of_test.cpp b/test/one_of_test.cpp index 22ccca2..8403a8e 100644 --- a/test/one_of_test.cpp +++ b/test/one_of_test.cpp @@ -92,10 +92,10 @@ void test_one () BOOST_CHECK (!ba::one_of_equal ( li.begin(), l_iter, 3 )); BOOST_CHECK (!ba::one_of ( li.begin(), l_iter, is_ ( 3 ))); - BOOST_CXX14_CONSTEXPR bool constexpr_res = ( - !ba::one_of ( some_numbers, is_ ( 6 )) - && ba::one_of ( some_numbers + 1, some_numbers + 3, is_ ( 1 )) - ); + BOOST_CXX14_CONSTEXPR bool constexpr_res = + !ba::one_of ( some_numbers, is_ ( 6 )) && + ba::one_of ( some_numbers + 1, some_numbers + 3, is_ ( 1 )) && + true; BOOST_CHECK ( constexpr_res ); }