Skip to content

Commit

Permalink
flat_map : operator[ ]を追加 #1078
Browse files Browse the repository at this point in the history
  • Loading branch information
faithandbrave committed May 18, 2023
1 parent e87272b commit 1fe5eb3
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 2 deletions.
2 changes: 1 addition & 1 deletion reference/flat_map/flat_map.md
Expand Up @@ -74,7 +74,7 @@ namespace std {
| 名前 | 説明 | 対応バージョン |
|---------------------------------------|--------------------------------------------|-------|
| [`operator[]`](flat_map/op_at.md.nolink) | 指定したキーを持つ要素を取得する | C++23 |
| [`operator[]`](flat_map/op_at.md) | 指定したキーを持つ要素を取得する | C++23 |
| [`at`](flat_map/at.md) | 指定したキーを持つ要素を取得する | C++23 |
| [`count`](flat_map/count.md.nolink) | 指定したキーにマッチする要素の数を取得する | C++23 |
| [`find`](flat_map/find.md.nolink) | 指定したキーで要素を探す | C++23 |
Expand Down
2 changes: 1 addition & 1 deletion reference/flat_map/flat_map/at.md
Expand Up @@ -70,5 +70,5 @@ exception std::out_of_range


## 関連項目
- [`operator[]`](op_at.md.nolink)
- [`operator[]`](op_at.md)
- [`find()`](find.md.nolink)
63 changes: 63 additions & 0 deletions reference/flat_map/flat_map/op_at.md
@@ -0,0 +1,63 @@
# operator[]
* flat_map[meta header]
* std[meta namespace]
* flat_map[meta class]
* function[meta id-type]
* cpp23[meta cpp]

```cpp
mapped_type& operator[](const key_type& x); // (1) C++23
mapped_type& operator[](key_type&& x); // (2) C++23
```

## 概要
指定したキーを持つ要素を取得する。対応する要素が存在しない場合は生成して返す。


## 戻り値
キー`x`に対応する値を返す。対応する要素が存在しない場合は、要素をデフォルト構築して参照を返す。


## 計算量
要素数に対して対数時間


##
```cpp example
#include <iostream>
#include <flat_map>

int main()
{
std::flat_map<int, char> fm;
fm.insert(std::make_pair(1, 'a'));

// キー`1`に対応する要素を参照する
char& a = fm[1];
std::cout << a << std::endl;

// キー`2`に対応する要素を生成する
fm[2] = 'b';
}
```
* m[1][color ff0000]
* m[2][color ff0000]
* m.insert[link insert.md.nolink]

### 出力
```
a
```

## バージョン
### 言語
- C++23

### 処理系
- [Clang](/implementation.md#clang): ??
- [GCC](/implementation.md#gcc): ??
- [Visual C++](/implementation.md#visual_cpp): ??


## 関連項目
- [`at()`](at.md)

0 comments on commit 1fe5eb3

Please sign in to comment.