命名空间
变体
操作

operator-(std::counted_iterator<I>, std::default_sentinel_t)

来自 cppreference.cn
 
 
迭代器库
迭代器概念
迭代器原语
算法概念与工具
间接可调用概念
常用算法要求
工具
迭代器适配器
 
 
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) [编辑]
前进迭代器
(function template) [编辑]
计算两个迭代器适配器之间的距离
(function template) [编辑]
用于知道其范围边界的迭代器的默认哨兵
(class) [编辑]