Skip to content

Commit 5e04103

Browse files
committed
flat_map : atを追加 #1078
1 parent 4f1dfeb commit 5e04103

File tree

2 files changed

+77
-2
lines changed

2 files changed

+77
-2
lines changed

reference/flat_map/flat_map.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ namespace std {
7575
| 名前 | 説明 | 対応バージョン |
7676
|---------------------------------------|--------------------------------------------|-------|
7777
| [`operator[]`](flat_map/op_at.md.nolink) | 指定したキーを持つ要素を取得する | C++23 |
78-
| [`at`](flat_map/at.md.nolink) | 指定したキーを持つ要素を取得する | C++23 |
78+
| [`at`](flat_map/at.md) | 指定したキーを持つ要素を取得する | C++23 |
7979
| [`count`](flat_map/count.md.nolink) | 指定したキーにマッチする要素の数を取得する | C++23 |
8080
| [`find`](flat_map/find.md.nolink) | 指定したキーで要素を探す | C++23 |
8181
| [`contains`](flat_map/contains.md.nolink) | 指定したキーの要素が含まれているかを判定する | C++23 |
@@ -175,7 +175,7 @@ int main()
175175
}
176176
}
177177
```
178-
* fm.at[link flat_map/at.md.nolink]
178+
* fm.at[link flat_map/at.md]
179179

180180
#### 出力
181181
```

reference/flat_map/flat_map/at.md

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# at
2+
* flat_map[meta header]
3+
* std[meta namespace]
4+
* flat_map[meta class]
5+
* function[meta id-type]
6+
* cpp23[meta cpp]
7+
8+
```cpp
9+
mapped_type& at(const key_type& x); // (1) C++23
10+
const mapped_type& at(const key_type& x) const; // (2) C++23
11+
```
12+
13+
## 概要
14+
指定したキーを持つ要素を取得する。
15+
要素を取り出す際にキーの存在チェックをする。
16+
17+
18+
## 戻り値
19+
キー`x`に対応する値を返す。対応する要素が存在しないときは、[`out_of_range`](/reference/stdexcept.md)例外を投げる。
20+
21+
22+
## 計算量
23+
要素数に対して対数時間
24+
25+
26+
## 例
27+
```cpp example
28+
#include <iostream>
29+
#include <flat_map>
30+
#include <stdexcept>
31+
32+
namespace stdx = flat_map;
33+
template<class Container, class T>
34+
void at_wrap(Container& c, T v)
35+
{
36+
try {
37+
std::cout << c.at(v) << std::endl;
38+
}
39+
catch(std::out_of_range&) {
40+
std::cout << "exception std::out_of_range" << std::endl;
41+
}
42+
}
43+
44+
int main()
45+
{
46+
stdx::flat_map<int,char> fm;
47+
fm.insert(std::make_pair(1, 'a'));
48+
49+
at_wrap(fm, 1);
50+
at_wrap(fm, 2);
51+
}
52+
```
53+
* c.at[color ff0000]
54+
* fm.insert[link insert.md.nolink]
55+
* std::out_of_range[link /reference/stdexcept.md]
56+
57+
### 出力
58+
```
59+
a
60+
exception std::out_of_range
61+
```
62+
63+
## バージョン
64+
### 言語
65+
- C++23
66+
67+
### 処理系
68+
- [Clang](/implementation.md#clang): ??
69+
- [GCC](/implementation.md#gcc): ??
70+
- [Visual C++](/implementation.md#visual_cpp): ??
71+
72+
73+
## 関連項目
74+
- [`operator[]`](op_at.md.nolink)
75+
- [`find()`](find.md.nolink)

0 commit comments

Comments
 (0)