|
| 1 | +# enumerate_view |
| 2 | +* ranges[meta header] |
| 3 | +* std::ranges[meta namespace] |
| 4 | +* class template[meta id-type] |
| 5 | +* cpp23[meta cpp] |
| 6 | + |
| 7 | +```cpp |
| 8 | +namespace std::ranges { |
| 9 | + template<view V> |
| 10 | + requires range-with-movable-references<V> |
| 11 | + class enumerate_view : public view_interface<enumerate_view<V>> { …… }; // (1) |
| 12 | + |
| 13 | + namespace views { |
| 14 | + inline constexpr /*unspecified*/ enumerate = /*unspecified*/; // (2) |
| 15 | + } |
| 16 | +} |
| 17 | +``` |
| 18 | +* range-with-movable-references[link range-with-movable-references.md.nolink] |
| 19 | +
|
| 20 | +## 概要 |
| 21 | +
|
| 22 | +`enumerate_view`はインデックスを付ける[`view`](view.md)。 |
| 23 | +
|
| 24 | +`enumerate_view`の要素は、インデックスと元のRangeの要素からなる[`tuple`](/reference/tuple/tuple.md)である。 |
| 25 | +
|
| 26 | +- (1): `enumerate_view`のクラス定義 |
| 27 | +- (2): `enumerate_view`を生成するRangeアダプタオブジェクト |
| 28 | +
|
| 29 | +### Rangeコンセプト |
| 30 | +
|
| 31 | +| borrowed | sized | output | input | forward | bidirectional | random_access | contiguous | common | viewable | view | |
| 32 | +|----------|-------|--------|-------|---------|---------------|---------------|------------|--------|----------|------| |
| 33 | +| | ※ | ※ | 〇 | ※ | ※ | ※ | | ※ | ○ | ○ | |
| 34 | +
|
| 35 | +- ※: 元となるRangeに従う |
| 36 | +
|
| 37 | +## 効果 |
| 38 | +
|
| 39 | +- (2): 式`views::enumerate(E)`の効果は`enumerate_view<`[`views::all_t`](all.md)`<decltype((E))>>(E)` と等しい |
| 40 | +
|
| 41 | +
|
| 42 | +## メンバ関数 |
| 43 | +
|
| 44 | +| 名前 | 説明 | 対応バージョン | |
| 45 | +|--------------------------------------------------|----------------------------------|----------------| |
| 46 | +| [`(constructor)`](enumerate_view/op_constructor.md.nolink) | コンストラクタ | C++23 | |
| 47 | +| [`base`](enumerate_view/base.md.nolink) | `V`の参照を取得する | C++23 | |
| 48 | +| [`begin`](enumerate_view/begin.md.nolink) | 先頭を指すイテレータを取得する | C++23 | |
| 49 | +| [`end`](enumerate_view/end.md.nolink) | 番兵を取得する | C++23 | |
| 50 | +| [`size`](enumerate_view/size.md.nolink) | 要素数を取得する | C++23 | |
| 51 | +
|
| 52 | +## 継承しているメンバ関数 |
| 53 | +
|
| 54 | +| 名前 | 説明 | 対応バージョン | |
| 55 | +|----------------------------------------------|-----------------------------------|----------------| |
| 56 | +| [`empty`](view_interface/empty.md) | Rangeが空かどうかを判定する | C++20 | |
| 57 | +| [`operator bool`](view_interface/op_bool.md) | Rangeが空でないかどうかを判定する | C++20 | |
| 58 | +| [`front`](view_interface/front.md) | 先頭要素への参照を取得する | C++20 | |
| 59 | +| [`back`](view_interface/back.md) | 末尾要素への参照を取得する | C++20 | |
| 60 | +| [`cbegin`](view_interface/cbegin.md) | 定数イテレータを取得する | C++23 | |
| 61 | +| [`cend`](view_interface/cend.md) | 定数イテレータ(番兵)を取得する | C++23 | |
| 62 | +| [`operator[]`](view_interface/op_at.md) | 要素へアクセスする | C++20 | |
| 63 | +
|
| 64 | +## 推論補助 |
| 65 | +
|
| 66 | +| 名前 | 説明 | 対応バージョン | |
| 67 | +|-------------------------------------------------------|------------------------------|----------------| |
| 68 | +| [`(deduction_guide)`](enumerate_view/op_deduction_guide.md.nolink) | クラステンプレートの推論補助 | C++23 | |
| 69 | +
|
| 70 | +## 例 |
| 71 | +```cpp example |
| 72 | +#include <ranges> |
| 73 | +#include <vector> |
| 74 | +#include <print> |
| 75 | +
|
| 76 | +int main() { |
| 77 | + const std::vector v = {'a', 'b', 'c'}; |
| 78 | +
|
| 79 | + std::println("{}", v | std::views::enumerate); |
| 80 | +} |
| 81 | +``` |
| 82 | +* std::views::enumerate[color ff0000] |
| 83 | + |
| 84 | +### 出力 |
| 85 | +``` |
| 86 | +[(0, 'a'), (1, 'b'), (2, 'c')] |
| 87 | +``` |
| 88 | + |
| 89 | +## バージョン |
| 90 | +### 言語 |
| 91 | +- C++23 |
| 92 | + |
| 93 | +### 処理系 |
| 94 | +- [Clang](/implementation.md#clang): ?? |
| 95 | +- [GCC](/implementation.md#gcc): ?? |
| 96 | +- [ICC](/implementation.md#icc): ?? |
| 97 | +- [Visual C++](/implementation.md#visual_cpp): ?? |
| 98 | + |
| 99 | +## 参照 |
| 100 | +- [N4950 26 Ranges library](https://timsong-cpp.github.io/cppwp/n4950/ranges) |
0 commit comments