std::experimental::ranges::lexicographical_compare
| 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) |
辞書順比較は、以下の特性を持つ操作です。
- 2つの範囲は要素ごとに比較されます。
- 最初に一致しない要素が、どちらの範囲が他方よりも辞書順で 小さい または 大きい かを定義します。
- 一方の範囲がもう一方の範囲のプレフィックスである場合、短い方の範囲が辞書順で 小さい とみなされます。
- 2つの範囲の要素が等しく、長さも同じ場合、その範囲は辞書順で 等しい とみなされます。
- 空の範囲は、任意の非空の範囲よりも辞書順で 小さい とみなされます。
- 2つの空の範囲は、辞書順で 等しい とみなされます。
目次 |
[編集] パラメータ
| first1, last1 | - | 調べる最初の要素の範囲 |
| r1 | - | 調べる最初の要素の範囲 |
| first2, last2 | - | 調べる2番目の要素の範囲 |
| r2 | - | 調べる2番目の要素の範囲 |
| comp | - | 射影された要素に適用する比較関数 |
| proj1 | - | 最初の範囲の要素に適用する射影 |
| proj2 | - | 2番目の範囲の要素に適用する射影 |
[編集] 戻り値
最初の範囲が2番目の範囲より辞書順で *小さい* 場合、`true` を返します。
[編集] 計算量
`N1 = last1 - first1` および `N2 = last2 - first2` とすると、比較操作の適用回数は最大で `2 * min(N1, N2)` 回です。
[編集] 実装例
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 を返す (関数テンプレート) | |
| 2つの要素の集合が同じかどうかを判断する (function template) |