最終更新日時(UTC):
が更新

履歴 編集

class template
<ranges>

std::ranges::enumerate_view(C++23)

namespace std::ranges {
  template<view V>
    requires range-with-movable-references<V>
  class enumerate_view : public view_interface<enumerate_view<V>> { …… }; // (1)

  namespace views {
    inline constexpr /*unspecified*/ enumerate = /*unspecified*/;      // (2)
  }
}

概要

enumerate_viewはインデックスを付けるview

enumerate_viewの要素は、インデックスと元のRangeの要素からなるtuple (tuple<range_difference_t<Base>,range_value_t<Base>>)である。

  • (1): enumerate_viewのクラス定義
  • (2): enumerate_viewを生成するRangeアダプタオブジェクト

Rangeコンセプト

borrowed sized output input forward bidirectional random_access contiguous common viewable view
  • ※: 元となるRangeに従う

効果

  • (2): 式views::enumerate(E)の効果はenumerate_view<views::all_t<decltype((E))>>(E) と等しい

メンバ関数

名前 説明 対応バージョン
(constructor) コンストラクタ C++23
base Vの参照を取得する C++23
begin 先頭を指すイテレータを取得する C++23
end 番兵を取得する C++23
size 要素数を取得する C++23

継承しているメンバ関数

名前 説明 対応バージョン
empty Rangeが空かどうかを判定する C++23
operator bool Rangeが空でないかどうかを判定する C++23
front 先頭要素への参照を取得する C++23
back 末尾要素への参照を取得する C++23
cbegin 定数イテレータを取得する C++23
cend 定数イテレータ(番兵)を取得する C++23
operator[] 要素へアクセスする C++23

推論補助

名前 説明 対応バージョン
(deduction_guide) クラステンプレートの推論補助 C++23

#include <iostream>
#include <ranges>
#include <vector>

int main() {
  const std::vector v = {'a', 'b', 'c'};

  for (auto [index, x] : v | std::views::enumerate) {
    std::cout << index << ' ' << x << std::endl;
  }
}

出力

0 a
1 b
2 c

バージョン

言語

  • C++23

処理系

参照