forked from boostorg/algorithm
find_{not,*backward} docs copy editing.
This commit is contained in:
@ -11,7 +11,7 @@ Distributed under the Boost Software License, Version 1.0.
|
|||||||
|
|
||||||
The header file 'find_backward.hpp' contains variants of the stl algorithm
|
The header file 'find_backward.hpp' contains variants of the stl algorithm
|
||||||
`find`. These variants are like `find`, except that the evaluate the elements
|
`find`. These variants are like `find`, except that the evaluate the elements
|
||||||
of the given sequence if reverse order.
|
of the given sequence in reverse order.
|
||||||
|
|
||||||
Consider how finding the last element that is equal to `x` in a range is
|
Consider how finding the last element that is equal to `x` in a range is
|
||||||
typically done:
|
typically done:
|
||||||
@ -23,7 +23,7 @@ typically done:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Raw loops are icky though. PErhaps we should do a bit of extra work to allow
|
Raw loops are icky though. Perhaps we should do a bit of extra work to allow
|
||||||
the use of `std::find()`:
|
the use of `std::find()`:
|
||||||
|
|
||||||
auto rfirst = std::make_reverse_iterator(last);
|
auto rfirst = std::make_reverse_iterator(last);
|
||||||
@ -31,31 +31,31 @@ the use of `std::find()`:
|
|||||||
auto it = std::find(rfirst, rlast);
|
auto it = std::find(rfirst, rlast);
|
||||||
// Use it here...
|
// Use it here...
|
||||||
|
|
||||||
That seems nicer, but it has two major drawbacks. First, it requires an
|
That seems nicer in that there is no raw loop, but it has two major drawbacks.
|
||||||
unpleasant amount of typing. Second, it is considerably less efficient than
|
First, it requires an unpleasant amount of typing. Second, it is less
|
||||||
forward-iterator `find` , since `std::reverse_iterator` calls its
|
efficient than forward-iterator `find` , since `std::reverse_iterator` calls
|
||||||
base-iterator's `operator--()` in most of its members before doing the work
|
its base-iterator's `operator--()` in most of its member functions before
|
||||||
that the member requires.
|
doing the work that the member function requires.
|
||||||
|
|
||||||
[heading interface]
|
[heading interface]
|
||||||
|
|
||||||
template<typename BidiIter, typename T>
|
template<typename BidiIter, typename T>
|
||||||
BidiIter find_backward(BidiIter first, BidiIter last, T const & x);
|
BidiIter find_backward(BidiIter first, BidiIter last, const T & x);
|
||||||
|
|
||||||
template<typename Range, typename T>
|
template<typename Range, typename T>
|
||||||
boost::range_iterator<Range> find_backward(Range & range, T const & x);
|
boost::range_iterator<Range> find_backward(Range & range, const T & x);
|
||||||
|
|
||||||
The function `find_backward` returns an iterator to the last element that is
|
These overloads of `find_backward` return an iterator to the last element that
|
||||||
equal to `x` in `[first, last)` or `r`, respectively.
|
is equal to `x` in `[first, last)` or `r`, respectively.
|
||||||
|
|
||||||
template<typename BidiIter, typename T>
|
template<typename BidiIter, typename T>
|
||||||
BidiIter find_not_backward(BidiIter first, BidiIter last, T const & x);
|
BidiIter find_not_backward(BidiIter first, BidiIter last, const T & x);
|
||||||
|
|
||||||
template<typename Range, typename T>
|
template<typename Range, typename T>
|
||||||
boost::range_iterator<Range> find_not_backward(Range & range, T const & x);
|
boost::range_iterator<Range> find_not_backward(Range & range, const T & x);
|
||||||
|
|
||||||
The function `find_not_backward` returns an iterator to the last element that
|
These overloads of `find_not_backward` return an iterator to the last element
|
||||||
is not equal to `x` in `[first, last)` or `r`, respectively.
|
that is not equal to `x` in `[first, last)` or `r`, respectively.
|
||||||
|
|
||||||
template<typename BidiIter, typename Pred>
|
template<typename BidiIter, typename Pred>
|
||||||
BidiIter find_if_backward(BidiIter first, BidiIter last, Pred p);
|
BidiIter find_if_backward(BidiIter first, BidiIter last, Pred p);
|
||||||
@ -63,8 +63,8 @@ is not equal to `x` in `[first, last)` or `r`, respectively.
|
|||||||
template<typename Range, typename Pred>
|
template<typename Range, typename Pred>
|
||||||
boost::range_iterator<Range> find_if_backward(Range & range, Pred p);
|
boost::range_iterator<Range> find_if_backward(Range & range, Pred p);
|
||||||
|
|
||||||
The function `find_if_backward` returns an iterator to the last element for
|
These overloads of `find_if_backward` return an iterator to the last element
|
||||||
which `pred` returns `true` in `[first, last)` or `r`, respectively.
|
for which `pred` returns `true` in `[first, last)` or `r`, respectively.
|
||||||
|
|
||||||
template<typename BidiIter, typename Pred>
|
template<typename BidiIter, typename Pred>
|
||||||
BidiIter find_if_not_backward(BidiIter first, BidiIter last, Pred p);
|
BidiIter find_if_not_backward(BidiIter first, BidiIter last, Pred p);
|
||||||
@ -72,8 +72,9 @@ which `pred` returns `true` in `[first, last)` or `r`, respectively.
|
|||||||
template<typename Range, typename Pred>
|
template<typename Range, typename Pred>
|
||||||
boost::range_iterator<Range> find_if_not_backward(Range & range, Pred p);
|
boost::range_iterator<Range> find_if_not_backward(Range & range, Pred p);
|
||||||
|
|
||||||
The function `find_if_not_backward` returns an iterator to the last element
|
These overloads of `find_if_not_backward` return an iterator to the last
|
||||||
for which `pred` returns `false` in `[first, last)` or `r`, respectively.
|
element for which `pred` returns `false` in `[first, last)` or `r`,
|
||||||
|
respectively.
|
||||||
|
|
||||||
[heading Examples]
|
[heading Examples]
|
||||||
|
|
||||||
|
@ -23,9 +23,7 @@ the first occurrance of any number besides `1` in `vec`? We have to write an
|
|||||||
unfortunate amount of code:
|
unfortunate amount of code:
|
||||||
|
|
||||||
auto std::vector<int> vec = { 1, 1, 2 };
|
auto std::vector<int> vec = { 1, 1, 2 };
|
||||||
auto it = std::find_if(
|
auto it = std::find_if(vec.begin(), vec.end(), [](int i) { return i != 1; });
|
||||||
vec.begin(), vec.end(),
|
|
||||||
[](int i) { return i != 1; });
|
|
||||||
|
|
||||||
With `find_not()` the code gets much more terse:
|
With `find_not()` the code gets much more terse:
|
||||||
|
|
||||||
@ -35,18 +33,18 @@ With `find_not()` the code gets much more terse:
|
|||||||
The existing `find` variants are: `find()`, `find_if()`, and `find_if_not()`.
|
The existing `find` variants are: `find()`, `find_if()`, and `find_if_not()`.
|
||||||
It seems natural to also have `find_not()`, for the very reason that we have
|
It seems natural to also have `find_not()`, for the very reason that we have
|
||||||
`find_if_not()` -- to avoid having to write a lambda to wrap the negation of
|
`find_if_not()` -- to avoid having to write a lambda to wrap the negation of
|
||||||
our find condition.
|
the find condition.
|
||||||
|
|
||||||
[heading interface]
|
[heading interface]
|
||||||
|
|
||||||
template<typename InputIter, typename Sentinel, typename T>
|
template<typename InputIter, typename Sentinel, typename T>
|
||||||
InputIter find_not(InputIter first, Sentinel last, T const & x);
|
InputIter find_not(InputIter first, Sentinel last, const T & x);
|
||||||
|
|
||||||
template<typename Range, typename T>
|
template<typename Range, typename T>
|
||||||
boost::range_iterator<Range> find_not(Range & r, T const & x);
|
boost::range_iterator<Range> find_not(Range & r, const T & x);
|
||||||
|
|
||||||
The function `find_not` returns the first value that is not equal to `x` in
|
These overloads of `find_not` return the first value that is not equal to `x`
|
||||||
the sequence `[first, last)` or `r`, respectively.
|
in the sequence `[first, last)` or `r`, respectively.
|
||||||
|
|
||||||
[heading Examples]
|
[heading Examples]
|
||||||
|
|
||||||
@ -57,7 +55,7 @@ Given the container `c1` containing `{ 0, 1, 2 }`, then
|
|||||||
|
|
||||||
[heading Iterator Requirements]
|
[heading Iterator Requirements]
|
||||||
|
|
||||||
`equal` works on all iterators except output iterators.
|
`find_not` works on all iterators except output iterators.
|
||||||
|
|
||||||
The template parameter `Sentinel` is allowed to be different from `InputIter`,
|
The template parameter `Sentinel` is allowed to be different from `InputIter`,
|
||||||
or they may be the same. For an `InputIter` `it` and a `Sentinel` `end`, `it
|
or they may be the same. For an `InputIter` `it` and a `Sentinel` `end`, `it
|
||||||
|
Reference in New Issue
Block a user