Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e87272b
commit 1fe5eb3
Showing
3 changed files
with
65 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |