Skip to content

Commit

Permalink
flat_map : atを追加 #1078
Browse files Browse the repository at this point in the history
  • Loading branch information
faithandbrave committed May 17, 2023
1 parent 4f1dfeb commit 5e04103
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 2 deletions.
4 changes: 2 additions & 2 deletions reference/flat_map/flat_map.md
Expand Up @@ -75,7 +75,7 @@ namespace std {
| 名前 | 説明 | 対応バージョン |
|---------------------------------------|--------------------------------------------|-------|
| [`operator[]`](flat_map/op_at.md.nolink) | 指定したキーを持つ要素を取得する | C++23 |
| [`at`](flat_map/at.md.nolink) | 指定したキーを持つ要素を取得する | 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 |
| [`contains`](flat_map/contains.md.nolink) | 指定したキーの要素が含まれているかを判定する | C++23 |
Expand Down Expand Up @@ -175,7 +175,7 @@ int main()
}
}
```
* fm.at[link flat_map/at.md.nolink]
* fm.at[link flat_map/at.md]

#### 出力
```
Expand Down
75 changes: 75 additions & 0 deletions reference/flat_map/flat_map/at.md
@@ -0,0 +1,75 @@
# at
* flat_map[meta header]
* std[meta namespace]
* flat_map[meta class]
* function[meta id-type]
* cpp23[meta cpp]

```cpp
mapped_type& at(const key_type& x); // (1) C++23
const mapped_type& at(const key_type& x) const; // (2) C++23
```
## 概要
指定したキーを持つ要素を取得する。
要素を取り出す際にキーの存在チェックをする。
## 戻り値
キー`x`に対応する値を返す。対応する要素が存在しないときは、[`out_of_range`](/reference/stdexcept.md)例外を投げる。
## 計算量
要素数に対して対数時間
## 例
```cpp example
#include <iostream>
#include <flat_map>
#include <stdexcept>
namespace stdx = flat_map;
template<class Container, class T>
void at_wrap(Container& c, T v)
{
try {
std::cout << c.at(v) << std::endl;
}
catch(std::out_of_range&) {
std::cout << "exception std::out_of_range" << std::endl;
}
}
int main()
{
stdx::flat_map<int,char> fm;
fm.insert(std::make_pair(1, 'a'));
at_wrap(fm, 1);
at_wrap(fm, 2);
}
```
* c.at[color ff0000]
* fm.insert[link insert.md.nolink]
* std::out_of_range[link /reference/stdexcept.md]

### 出力
```
a
exception std::out_of_range
```

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

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


## 関連項目
- [`operator[]`](op_at.md.nolink)
- [`find()`](find.md.nolink)

0 comments on commit 5e04103

Please sign in to comment.