|
| 1 | +[/ File find_last.qbk] |
| 2 | + |
| 3 | +[section:find_last find_last, find_last_if, find_last_if_not ] |
| 4 | + |
| 5 | +[/license |
| 6 | +Copyright (c) 2022 T. Zachary Laine |
| 7 | + |
| 8 | +Distributed under the Boost Software License, Version 1.0. |
| 9 | +(See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
| 10 | +] |
| 11 | + |
| 12 | +The header file 'find_last.hpp' contains variants of the stl algorithm |
| 13 | +`find`. These variants are like `find`, except that they find the last |
| 14 | +instance of an element instead of the first. |
| 15 | + |
| 16 | +The functions in this header are as close to the ones in C++23's `std::ranges` |
| 17 | +namespace as possible. In C++20 builds, they are constrained exactly as the |
| 18 | +standard does it. They each return a `boost::algorithm::subrange`, which is a |
| 19 | +mostly-API-compatible version of `std::ranges::subrange`. It's differences |
| 20 | +from the C++20 `subrange` are that it does not support sized ranges, and that |
| 21 | +it cannot be implicitly converted to a pair-like type. |
| 22 | + |
| 23 | +[heading interface] |
| 24 | + |
| 25 | + template<typename ForwardIterator, typename Sentinel, typename T, typename Proj = identity> |
| 26 | + BOOST_CXX14_CONSTEXPR subrange<ForwardIterator> |
| 27 | + find_last(ForwardIterator first, Sentinel last, const T & value, Proj proj = {}) |
| 28 | + |
| 29 | + template<typename R, typename T, typename Proj = identity> |
| 30 | + BOOST_CXX14_CONSTEXPR subrange<iterator_t<R>> |
| 31 | + find_last(R && r, const T & value, Proj proj = {}) |
| 32 | + |
| 33 | +These overloads of `find_last` return a subrange `[it, end)`, where `it` is |
| 34 | +the position of the last element that is equal to `x` in the given range, and |
| 35 | +`end` is the end of the given range. |
| 36 | + |
| 37 | + template<typename ForwardIterator, typename Sentinel, typename Pred, typename Proj = identity> |
| 38 | + BOOST_CXX14_CONSTEXPR subrange<ForwardIterator> |
| 39 | + find_last_if(ForwardIterator first, Sentinel last, Pred pred, Proj proj = {}) |
| 40 | + |
| 41 | + template<typename R, typename Pred, typename Proj = identity> |
| 42 | + BOOST_CXX14_CONSTEXPR subrange<iterator_t<R>> |
| 43 | + find_last_if(R && r, Pred pred, Proj proj = {}) |
| 44 | + |
| 45 | +These overloads of `find_if_last` return a subrange `[it, end)`, where `it` is |
| 46 | +the position of the last element for which `pred` returns `true` in the given |
| 47 | +range, and `end` is the end of the given range. |
| 48 | + |
| 49 | + template<typename ForwardIterator, typename Sentinel, typename Pred, typename Proj = identity> |
| 50 | + BOOST_CXX14_CONSTEXPR subrange<ForwardIterator> |
| 51 | + find_last_if_not(ForwardIterator first, Sentinel last, Pred pred, Proj proj = {}) |
| 52 | + |
| 53 | + template<typename R, typename Pred, typename Proj = identity> |
| 54 | + BOOST_CXX14_CONSTEXPR subrange<iterator_t<R>> |
| 55 | + find_last_if_not(R && r, Pred pred, Proj proj = {}) |
| 56 | + |
| 57 | +These overloads of `find_if_last` return a subrange `[it, end)`, where `it` is |
| 58 | +the position of the last element for which `pred` returns `false` in the given |
| 59 | +range, and `end` is the end of the given range. |
| 60 | + |
| 61 | +[heading Examples] |
| 62 | + |
| 63 | +Given the container `c1` containing `{ 2, 1, 2 }`, then |
| 64 | + |
| 65 | + find_last ( c1.begin(), c1.end(), 2 ) --> --c1.end() |
| 66 | + find_last ( c1.begin(), c1.end(), 3 ) --> c1.end() |
| 67 | + find_last_if ( c1.begin(), c1.end(), [](int i) {return i == 2;} ) --> --c1.end() |
| 68 | + find_last_if ( c1.begin(), c1.end(), [](int i) {return i == 3;} ) --> c1.end() |
| 69 | + find_last_if_not ( c1.begin(), c1.end(), [](int i) {return i == 2;} ) --> std::prev(c1.end(), 2) |
| 70 | + find_last_if_not ( c1.begin(), c1.end(), [](int i) {return i == 1;} ) --> c1.end() |
| 71 | + |
| 72 | +[heading Iterator Requirements] |
| 73 | + |
| 74 | +All variants work on forward iterators. |
| 75 | + |
| 76 | +[heading Complexity] |
| 77 | + |
| 78 | +Linear. |
| 79 | + |
| 80 | +[heading Exception Safety] |
| 81 | + |
| 82 | +All of the variants take their parameters by value and do not depend upon any |
| 83 | +global state. Therefore, all the routines in this file provide the strong |
| 84 | +exception guarantee. |
| 85 | + |
| 86 | +[heading Notes] |
| 87 | + |
| 88 | +All variants are `constexpr` in C++14 or later. |
| 89 | + |
| 90 | +[endsect] |
| 91 | + |
| 92 | +[/ File find_last.qbk |
| 93 | +Copyright 2022 T. Zachary Laine |
| 94 | +Distributed under the Boost Software License, Version 1.0. |
| 95 | +(See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt). |
| 96 | +] |
0 commit comments