Namespaces
Variants

std:: weakly_incrementable

From cppreference.net
Iterator library
Iterator concepts
weakly_incrementable
(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 I >

concept weakly_incrementable =
std:: movable < I > &&
requires ( I i ) {
typename std:: iter_difference_t < I > ;
requires /*is-signed-integer-like*/ < std:: iter_difference_t < I >> ;
{ ++ i } - > std:: same_as < I & > ; // 不要求保持相等性
i ++ ; // 不要求保持相等性

} ;
(C++20 起)

关于 /*is-signed-integer-like*/ 的定义,请参阅 is-integer-like 。

此概念规定了可通过前置与后置递增运算符进行自增的类型要求,但这些递增操作不一定是 保等性的 ,且类型本身不要求满足 std::equality_comparable

对于 std::weakly_incrementable 类型, a == b 并不意味 ++ a == ++ b 成立。针对弱可递增类型的算法必须是单遍算法。这些算法可通过 std::istream_iterator 将输入流作为数据源使用。

语义要求

对于类型为 I 的对象 i ,当且仅当满足以下所有条件时, I 才满足 std::weakly_incrementable 概念:

  • 表达式 ++ i i ++ 具有相同的定义域。
  • i 可递增,则 ++ i i ++ 均会使 i 向前推进。
  • i 可递增,则 std:: addressof ( ++ i ) == std:: addressof ( i )

缺陷报告

下列行为变更缺陷报告被追溯应用于先前发布的 C++ 标准。

缺陷报告 应用于 发布时行为 正确行为
P2325R3 C++20 要求具备 default_initializable 不作要求

参见

规定对 weakly_incrementable 类型的递增操作是 保等性的 ,且该类型是 equality_comparable
(概念)