名前空間
変種
操作

名前付き要件: LegacyRandomAccessIterator

提供: cppreference.com
< cpp‎ | named req
 
 
名前付き要件
基本
型の性質
ライブラリ全体
コンテナ
コンテナの要素
イテレータ
ストリーム入出力
乱数
並行処理
(C++11)

(C++11)
(C++11)
その他
 

LegacyRandomAccessIterator は定数時間で任意の要素を指す位置に移動できる LegacyBidirectionalIterator です。

配列要素へのポインタは LegacyRandomAccessIterator のすべての要件を満たします。

[編集] 要件

以下の内容を満たす場合、型 ItLegacyRandomAccessIterator を満たします。

さらに、

  • std::iterator_traits<It>::value_type によって表される型 value_type
  • std::iterator_traits<It>::difference_type によって表される型 difference_type
  • std::iterator_traits<It>::reference によって表される型 reference
  • It または const It 型のオブジェクト i, a, b
  • It& 型の値 r
  • difference_type 型の整数 n

が与えられたとき、以下の式が有効でなければならず、指定された効果を持たなければなりません。

戻り値の型 操作的意味論 注釈
r += n It& difference_type m = n;

if (m >= 0) while (m--) ++r;
else while (m++) --r;
return r;

  • n は正でも負でも構いません
  • 計算量は定数時間です (つまり、実装は操作的意味論に示されている while ループを実際に実行してはなりません)
a + n

n + a

It It temp = a;

return temp += n;

  • n は正でも負でも構いません
  • a + n == n + a
r -= n It& return r += -n; n の絶対値は difference_type の表現可能な値の範囲内でなければなりません
i - n It It temp = i;
return temp -= n;
b - a difference_type return n;

事前条件:

  • a+n==b であるような difference_type 型の値 n が存在する

事後条件:

  • b == a + (b - a)
i[n] reference に変換可能 *(i + n)
a < b 文脈的に bool に変換可能 b - a > 0 狭義全順序関係:
  • !(a < a)
  • a < b であれば !(b < a) が成り立つ
  • a < b かつ b < c であれば a < c が成り立つ
  • a < b ま���は b < a または a == b
    (これらの式のいずれかひとつだけが真である)
a > b 文脈的に bool に変換可能 b < a a < b と逆の全順序関係
a >= b 文脈的に bool に変換可能 !(a < b)
a <= b 文脈的に bool に変換可能 !(a > b)

上記のルールは LegacyRandomAccessIteratorLessThanComparable も実装することを暗に示します。

可変LegacyRandomAccessIteratorLegacyOutputIterator の要件を追加でサポートする LegacyRandomAccessIterator です。

コンセプト

std::iterator_traits の定義のために、以下の説明専用コンセプトが定義されます。

template<class I>

concept __LegacyRandomAccessIterator =
  __LegacyBidirectionalIterator<I> && std::totally_ordered<I> &&
  requires(I i, typename std::incrementable_traits<I>::difference_type n) {
    { i += n } -> std::same_as<I&>;
    { i -= n } -> std::same_as<I&>;
    { i +  n } -> std::same_as<I>;
    { n +  i } -> std::same_as<I>;
    { i -  n } -> std::same_as<I>;
    { i -  i } -> std::same_as<decltype(n)>;
    {  i[n]  } -> std::convertible_to<std::iter_reference_t<I>>;

  };

説明専用コンセプト __LegacyBidirectionalIteratorLegacyBidirectionalIterator#Concept で説明されています。

(C++20以上)

[編集] 関連項目

BidirectionalIterator が定数時間の前進と添字アクセスをサポートするランダムアクセスイテレータであることを指定します
(コンセプト) [edit]