Merge pull request #50 from tzlaine/develop

Fix sloppy find_not() and find_*backward() code examples.
This commit is contained in:
Marshall Clow
2018-10-02 15:36:56 -07:00
committed by GitHub
2 changed files with 4 additions and 4 deletions

View File

@ -28,7 +28,7 @@ the use of `std::find()`:
auto rfirst = std::make_reverse_iterator(last);
auto rlast = std::make_reverse_iterator(first);
auto it = std::find(rfirst, rlast);
auto it = std::find(rfirst, rlast, x);
// Use it here...
That seems nicer in that there is no raw loop, but it has two major drawbacks.

View File

@ -15,19 +15,19 @@ equal to the given value.
Consider this use of `find()`:
auto std::vector<int> vec = { 1, 1, 2 };
std::vector<int> vec = { 1, 1, 2 };
auto it = std::find(vec.begin(), vec.end(), 1);
This gives us the first occurance of `1` in `vec`. What if we want to find
the first occurrance of any number besides `1` in `vec`? We have to write an
unfortunate amount of code:
auto std::vector<int> vec = { 1, 1, 2 };
std::vector<int> vec = { 1, 1, 2 };
auto it = std::find_if(vec.begin(), vec.end(), [](int i) { return i != 1; });
With `find_not()` the code gets much more terse:
auto std::vector<int> vec = { 1, 1, 2 };
std::vector<int> vec = { 1, 1, 2 };
auto it = find_not(vec.begin(), vec.end(), 1);
The existing `find` variants are: `find()`, `find_if()`, and `find_if_not()`.