operator-(std::counted_iterator<I>, std::default_sentinel_t)
来自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 为参数的关联类时由实参依赖查找找到。
参数
| 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) }
参阅
|    推进或回退迭代器   (公开成员函数)  | |
|    (C++20)  | 
  令迭代器前进  (函数模板)  | 
|    (C++20)  | 
  计算两个迭代器适配器间的距离  (函数模板)  | 
|    (C++20)  | 
  用于知晓其边界的迭代器的默认哨位  (类)  |