Namespaces
Variants

std:: sized_sentinel_for, std:: disable_sized_sentinel_for

From cppreference.net
Iterator library
Iterator concepts
sized_sentinel_for
(C++20)

Iterator primitives
Algorithm concepts and utilities
Indirect callable concepts
Common algorithm requirements
(C++20)
(C++20)
(C++20)
Utilities
(C++20)
Iterator adaptors
Range access
(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 未限定的非数组对象类型 S I 特化 disable_sized_sentinel_for ,只要其中至少有一个是 程序定义类型 。此类特化可用于 常量表达式 ,且具有类型 const bool

目录

语义要求

i 为类型 I 的迭代器, s 为类型 S 的哨位,使得 [ i , s ) 表示一个区间。设 n 为使 bool ( i == s ) true 所需应用 ++ i 的最小次数。当且仅当满足以下所有条件时, I S 才建模 sized_sentinel_for<S, I>

等值保持性

标准库概念的 requires 表达式 中声明的表达式必须满足 等值保持 要求(除非另有说明)。

隐式表达式变体

一个 requires 表达式 若使用了对于某个常量左值操作数不可修改的表达式,则同时需要 隐式表达式变体

参见

指定范围能在常数时间内获知其大小
(概念)
返回等于范围大小的整数
(定制点对象)