diff --git a/doc/find_not.qbk b/doc/find_not.qbk index 146f8c9..8d26185 100644 --- a/doc/find_not.qbk +++ b/doc/find_not.qbk @@ -42,6 +42,9 @@ our find condition. template InputIter find_not(InputIter first, Sentinel last, T const & x); + template + typename boost::range_iterator::type find_not(Range & r, T const & x); + The function `find_not` returns the first value in the sequence `[first, last)` that is not equal to `x`. diff --git a/include/boost/algorithm/find_not.hpp b/include/boost/algorithm/find_not.hpp index 420372b..8934738 100644 --- a/include/boost/algorithm/find_not.hpp +++ b/include/boost/algorithm/find_not.hpp @@ -8,13 +8,17 @@ #define BOOST_ALGORITHM_FIND_NOT_HPP #include +#include +#include + #include namespace boost { namespace algorithm { template -BOOST_CXX14_CONSTEXPR InputIter find_not(InputIter first, Sentinel last, T const & x) +BOOST_CXX14_CONSTEXPR +InputIter find_not(InputIter first, Sentinel last, T const & x) { for (; first != last; ++first) { if (*first != x) @@ -23,6 +27,13 @@ BOOST_CXX14_CONSTEXPR InputIter find_not(InputIter first, Sentinel last, T const return first; } +template +BOOST_CXX14_CONSTEXPR +typename boost::range_iterator::type find_not(Range & r, T const & x) +{ + return ::boost::algorithm::find_not(boost::begin(r), boost::end(r), x); +} + }} // namespace boost and algorithm #endif // BOOST_ALGORITHM_FIND_NOT_HPP diff --git a/test/find_not_test.cpp b/test/find_not_test.cpp index 40b0b71..6b4c2f3 100644 --- a/test/find_not_test.cpp +++ b/test/find_not_test.cpp @@ -43,13 +43,22 @@ BOOST_CXX14_CONSTEXPR bool check_constexpr() const int* start = ba::find_not(from, to, 1); // stops on first res = (res && start == from); + start = ba::find_not(in_data, 1); // stops on first + res = (res && start == from); + int in_data_2[] = {6, 6, 6, 6, 6}; const int* end = ba::find_not(in_data_2, in_data_2 + 5, 6); // stops on the end res = (res && end == in_data_2 + 5); + end = ba::find_not(in_data_2, 6); // stops on the end + res = (res && end == in_data_2 + 5); + const int* three = ba::find_not(from, to, 2); // stops on third element res = (res && three == in_data + 2); + three = ba::find_not(in_data, 2); // stops on third element + res = (res && three == in_data + 2); + return res; } @@ -67,12 +76,20 @@ void test_sequence() BOOST_CHECK_EQUAL( dist(ba::find_not(v1.begin(), v1.end(), v1.front())), 1); + BOOST_CHECK_EQUAL(dist(ba::find_not(v1, 0)), 0); + BOOST_CHECK_EQUAL(dist(ba::find_not(v1, v1.back())), 0); + BOOST_CHECK_EQUAL(dist(ba::find_not(v1, v1.front())), 1); + v1 = std::vector(10, 2); BOOST_CHECK_EQUAL(dist(ba::find_not(v1.begin(), v1.end(), 0)), 0); BOOST_CHECK_EQUAL( dist(ba::find_not(v1.begin(), v1.end(), v1.back())), v1.size()); BOOST_CHECK_EQUAL( dist(ba::find_not(v1.begin(), v1.end(), v1.front())), v1.size()); + + BOOST_CHECK_EQUAL(dist(ba::find_not(v1, 0)), 0); + BOOST_CHECK_EQUAL(dist(ba::find_not(v1, v1.back())), v1.size()); + BOOST_CHECK_EQUAL(dist(ba::find_not(v1, v1.front())), v1.size()); } // With bidirectional iterators. @@ -88,6 +105,10 @@ void test_sequence() BOOST_CHECK_EQUAL( dist(ba::find_not(l1.begin(), l1.end(), l1.front())), 1); + BOOST_CHECK_EQUAL(dist(ba::find_not(l1, 0)), 0); + BOOST_CHECK_EQUAL(dist(ba::find_not(l1, l1.back())), 0); + BOOST_CHECK_EQUAL(dist(ba::find_not(l1, l1.front())), 1); + l1.clear(); for (int i = 0; i < 10; ++i) l1.push_back(2); @@ -96,6 +117,10 @@ void test_sequence() dist(ba::find_not(l1.begin(), l1.end(), l1.back())), l1.size()); BOOST_CHECK_EQUAL( dist(ba::find_not(l1.begin(), l1.end(), l1.front())), l1.size()); + + BOOST_CHECK_EQUAL(dist(ba::find_not(l1, 0)), 0); + BOOST_CHECK_EQUAL(dist(ba::find_not(l1, l1.back())), l1.size()); + BOOST_CHECK_EQUAL(dist(ba::find_not(l1, l1.front())), l1.size()); } BOOST_CXX14_CONSTEXPR bool ce_result = check_constexpr();