std::random_access_iterator_C++中文网

  concept random_access_iterator =
    std::bidirectional_iterator<I> &&
    std::derived_from</*ITER_CONCEPT*/<I>, std::random_access_iterator_tag> &&
    std::totally_ordered<I> &&
    std::sized_sentinel_for<I, I> &&
    requires(I i, const I j, const std::iter_difference_t<I> n) {
      { i += n } -> std::same_as<I&>;
      { j +  n } -> std::same_as<I>;
      { n +  j } -> std::same_as<I>;
      { i -= n } -> std::same_as<I&>;
      { j -  n } -> std::same_as<I>;
      {  j[n]  } -> std::same_as<std::iter_reference_t<I>>;

   

};

概念 random_access_iterator 细化 bidirectional_iterator ,添加用 +=-=+- 运算符的常数时间前进、用 - 的常数时间距离计算,及带下标的数组记法支持。

abI 类型的合法迭代器,使得从 a 可抵达 b ,并令 n 为等于 b - astd::iter_difference_t<I> 类型值。 random_access_iterator<I> 仅若其所蕴含的概念均被实现并且符合下列条件才得到实现:

使用不修改某 const 左值运算数的表达式的 requires 表达式亦隐式要求该表达式的额外变种对给定运算数接受非 const 左值或(可为 const 的)右值,除非以有区别的语义显式要求这种表达式变种。这些隐式表达式变种必须符合与声明的表达式的相同的语义。不指定实现以何种程度校验变种的语法。