std::sized_sentinel_for, std::disable_sized_sentinel_for
|
在标头
<iterator> 定义 |
||
|
template< class S, class I >
concept sized_sentinel_for = |
(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 的迭代器与哨位满足该概念。语义要求
令 i 为 I 类型的迭代器,而 s 为 S 类型的哨位,使得 [i, s) 代表一个范围。令 n 为需要应用 ++i 以令 bool(i == s) 为 true 的最小次数。那么 S 和 I 只有在满足以下所有条件时才会实现 sized_sentinel_for<S, I>:
- 如果 n 能以 ranges::difference_type_t<I> 表示,那么 s - i 良定义并等于 n。
- 如果 -n 能以 ranges::difference_type_t<I> 表示,那么 i - s 良定义并等于 -n。
相等性保持
标准库概念的 requires 表达式中声明的表达式都要求保持相等性(除非另外说明)。
隐式表达式变种
使用了不修改某常量左值操作数的表达式的 requires 表达式,也会要求其隐式的表达式变种。
参阅
|
(C++20)
|
指定类型为可在常数时间内知晓大小的范围 (概念) |
|
(C++20)
|
返回等于范围大小的整数 (定制点对象) |