std::experimental::ranges::lexicographical_compare
| Technical Specification | ||||
| Filesystem library (filesystem TS) | ||||
| Library fundamentals (library fundamentals TS) | ||||
| Library fundamentals 2 (library fundamentals TS v2) | ||||
| Library fundamentals 3 (library fundamentals TS v3) | ||||
| Extensions for parallelism (parallelism TS) | ||||
| Extensions for parallelism 2 (parallelism TS v2) | ||||
| Extensions for concurrency (concurrency TS) | ||||
| Extensions for concurrency 2 (concurrency TS v2) | ||||
| Concepts (concepts TS) | ||||
| Ranges (ranges TS) | ||||
| Reflection (reflection TS) | ||||
| Mathematical special functions (special functions TR) | ||||
| Experimental Non-TS | ||||
| Pattern Matching | ||||
| Linear Algebra | ||||
| std::execution | ||||
| Contracts | ||||
| 2D Graphics |
| Non-modifying sequence operations | ||||
| Modifying sequence operations | ||||
| Partitioning operations | ||||
| Sorting operations | ||||
| Binary search operations | ||||
| Set operations (on sorted ranges) | ||||
| Heap operations | ||||
| Minimum/maximum operations | ||||
| Permutations | ||||
| Defined in header <experimental/ranges/algorithm>
|
||
| template< InputIterator I1, Sentinel<I1> S1, InputIterator I2, Sentinel<I2> S2, class Proj1 = ranges::identity, class Proj2 = ranges::identity, |
(1) | (ranges TS) |
| template< InputRange R1, InputRange R2, class Proj1 = ranges::identity, class Proj2 = ranges::identity, |
(2) | (ranges TS) |
[first1, last1) is lexicographically less than the second range [first2, last2). Elements are compared using the given binary comparison function comp, after being projected with proj1 and proj2 respectively.Lexicographical comparison is an operation with the following properties:
- Two ranges are compared element by element.
- The first mismatching element defines which range is lexicographically less or greater than the other.
- If one range is a prefix of another, the shorter range is lexicographically less than the other.
- If two ranges have equivalent elements and are of the same length, then the ranges are lexicographically equal.
- An empty range is lexicographically less than any non-empty range.
- Two empty ranges are lexicographically equal.
Contents |
[edit] Parameters
| first1, last1 | - | the first range of elements to examine |
| r1 | - | the first range of elements to examine |
| first2, last2 | - | the second range of elements to examine |
| r2 | - | the second range of elements to examine |
| comp | - | comparison function to apply to the projected elements |
| proj1 | - | projection to apply to the elements in the first range |
| proj2 | - | projection to apply to the elements in the second range |
[edit] Return value
true if the first range is lexicographically less than the second.
[edit] Complexity
At most 2·min(N1, N2) applications of the comparison operation, where N1 = last1 - first1 and N2 = last2 - first2.
[edit] Possible implementation
template<InputIterator I1, Sentinel<I1> S1, InputIterator I2, Sentinel<I2> S2, class Proj1 = ranges::identity, class Proj2 = ranges::identity, class Comp = ranges::less<>> requires IndirectStrictWeakOrder<Comp, projected<I2, Proj2>> bool lexicographical_compare(I1 first1, S1 last1, I2 first2, S2 last2, Comp comp = Comp{}, Proj1 proj1 = Proj1{}, Proj2 proj2 = Proj2{}) { for (; (first1 != last1) && (first2 != last2); (void) ++first1, (void) ++first2) { if (ranges::invoke(comp, ranges::invoke(proj1, *first1), ranges::invoke(proj2, *first2)) return true; if (ranges::invoke(comp, ranges::invoke(proj2, *first2), ranges::invoke(proj1, *first1)) return false; } return (first1 == last1) && (first2 != last2); } |
[edit] Example
| This section is incomplete Reason: no example |
[edit] See also
| returns true if one range is lexicographically less than another (function template) [edit] | |
| determines if two sets of elements are the same (function template) [edit] |