operator-(std::counted_iterator<I>, std::default_sentinel_t)
From cppreference.com
< cpp | iterator | counted iterator
| friend constexpr std::iter_difference_t<I> operator-( const counted_iterator& x, std::default_sentinel_t ); |
(1) | (C++20以降) |
| friend constexpr std::iter_difference_t<I> operator-( std::default_sentinel_t, const counted_iterator& y ); |
(2) | (C++20以降) |
1) 末尾までの負の距離を返します。
2) 末尾までの正の距離を返します。
この関数テンプレートは、通常の非修飾または修飾ルックアップからは見えず、std::counted_iterator<I> が引数の関連クラスである場合にのみ、引数依存の名前探索によって見つけることができます。
目次 |
[編集] パラメータ
| x, y | - | 差を計算するイテレータアダプタ |
[編集] 戻り値
1) -x.count()
2) y.count()
[編集] 例
このコードを実行
#include <initializer_list> #include <iterator> int main() { constexpr static auto v = {1, 2, 3, 4}; constexpr std::counted_iterator<std::initializer_list<int>::iterator> it{v.begin(), 3}; constexpr auto d1 = it - std::default_sentinel; static_assert(d1 == -3); // (1) constexpr auto d2 = std::default_sentinel - it; static_assert(d2 == +3); // (2) }
[編集] 関連項目
counted_iteratorを進める、またはデクリメントする(public member function) | |
| (C++20) |
イテレータを進める (関数テンプレート) |
| (C++20) |
2つのイテレータアダプタ間の距離を計算する (関数テンプレート) |
| (C++20) |
範囲の境界を知っているイテレータと共に使用するためのデフォルトの番兵 (sentinel) (クラス) |