命名空间
变体
操作

std::sized_sentinel_for, std::disable_sized_sentinel_for

来自 cppreference.cn
 
 
迭代器库
迭代器概念
sized_sentinel_for
(C++20)

迭代器原语
算法概念与工具
间接可调用概念
常用算法要求
(C++20)
(C++20)
(C++20)
工具
(C++20)
迭代器适配器
范围访问
(C++11)(C++14)
(C++14)(C++14)  
(C++11)(C++14)
(C++14)(C++14)  
(C++17)(C++20)
(C++17)
(C++17)
 
定义于头文件 <iterator>
template< class S, class I >

    concept sized_sentinel_for =
        std::sentinel_for<S, I> &&
        !std::disable_sized_sentinel_for<std::remove_cv_t<S>,
                                         std::remove_cv_t<I>> &&
        requires(const I& i, const S& s) {
            { s - i } -> std::same_as<std::iter_difference_t<I>>;
            { i - s } -> std::same_as<std::iter_difference_t<I>>;

        };
(1) (C++20 起)
template< class S, class I >
    inline constexpr bool disable_sized_sentinel_for = false;
(2) (C++20 起)
1) sized_sentinel_for 概念指定了迭代器类型 I 的对象和哨兵类型 S 的对象可以相减,以常数时间计算它们之间的距离。
2) disable_sized_sentinel_for 变量模板可用于防止可以相减但实际上不符合 sized_sentinel_for 模型的迭代器和哨兵满足该概念。
程序可以为 cv 非限定的非数组对象类型 SI 特化 disable_sized_sentinel_for,只要其中至少有一个是程序定义的类型。此类特化可在常量表达式中使用,并且类型为 const bool

目录

[编辑] 语义要求

i 为类型 I 的迭代器,s 为类型 S 的哨兵,使得 [is) 表示一个范围。令 n 为使 bool(i == s)true 所必需的 ++i 的最小应用次数。仅当所有以下条件都满足时,IS 才符合 sized_sentinel_for<S, I> 模型:

[编辑] 相等性保持

标准库概念的 requires 表达式中声明的表达式要求是相等性保持的(除非另有说明)。

[编辑] 隐式表达式变体

一个使用了对某些常量左值操作数而言非修改表达式的 requires 表达式,也需要隐式表达式变体

[编辑] 参阅

指定范围在常数时间内知道其大小
(概念) [编辑]
返回等于范围大小的整数
(自定义点对象)[编辑]