std::experimental::ranges::lexicographical_compare
定義於標頭檔案 <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)
是否按字典順序“小於”第二個範圍 [
first2,
last2)
。元素透過給定的二元比較函式 comp 比較,之前分別經過 proj1 和 proj2 投射。字典序比較是一種具有以下屬性的操作:
- 兩個範圍逐元素進行比較。
- 第一個不匹配的元素定義了哪個範圍在字典序上小於或大於另一個。
- 如果一個範圍是另一個範圍的字首,則較短的範圍在字典序上小於另一個。
- 如果兩個範圍具有等效元素且長度相同,則這兩個範圍在字典序上相等。
- 空範圍在字典序上小於任何非空範圍。
- 兩個空範圍在字典序上相等。
目錄 |
[編輯] 引數
first1, last1 | - | 要檢查的第一個元素範圍 |
r1 | - | 要檢查的第一個元素範圍 |
first2, last2 | - | 要檢查的第二個元素範圍 |
r2 | - | 要檢查的第二個元素範圍 |
comp | - | 應用於投影元素的比較函式 |
proj1 | - | 應用於第一個範圍元素的投影。 |
proj2 | - | 應用於第二個範圍元素的投影。 |
[編輯] 返回值
如果第一個範圍字典序“小於”第二個範圍,則返回 true。
[編輯] 複雜度
最多執行 2·min(N1, N2) 次比較操作,其中 N1 = last1 - first1 且 N2 = last2 - first2。
[編輯] 可能的實現
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<I1, Proj1>, 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); } |
[編輯] 示例
本節不完整 原因:無示例 |
[編輯] 參閱
如果一個範圍在字典上小於另一個範圍,則返回 true (函式模板) | |
判斷兩組元素是否相同 (函式模板) |