Skip to content

Commit f28cc8b

Browse files
committed
add swap_free.md to flat_map (#1078)
1 parent 2a1427f commit f28cc8b

File tree

4 files changed

+168
-2
lines changed

4 files changed

+168
-2
lines changed

reference/flat_map/flat_map.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ namespace std {
142142
143143
| 名前 | 説明 | 対応バージョン |
144144
|------|------|----------------|
145-
| [`swap`](flat_map/swap_free.md.nolink) | 2つの`flat_map`オブジェクトを入れ替える | C++23 |
145+
| [`swap`](flat_map/swap_free.md) | 2つの`flat_map`オブジェクトを入れ替える | C++23 |
146146
147147
148148
## 推論補助
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# swap (非メンバ関数)
2+
* flat_map[meta header]
3+
* std[meta namespace]
4+
* function template[meta id-type]
5+
* cpp23[meta cpp]
6+
7+
```cpp
8+
namespace std {
9+
template <class Key, class T, class Compare, class KeyContainer class MappedContainer>
10+
void swap(flat_map<Key, T, Compare, KeyContainer MappedContainer>& x,
11+
flat_map<Key, T, Compare, KeyContainer MappedContainer>& y); // (1) C++23
12+
}
13+
```
14+
15+
## 概要
16+
2つの `flat_map` オブジェクトを入れ替える。
17+
18+
19+
## 効果
20+
`x.`[`swap`](swap.md)`(y)`
21+
22+
23+
## 例
24+
```cpp example
25+
#include <flat_map>
26+
#include <iostream>
27+
28+
template <class Map>
29+
void print(const char* name, const Map& m)
30+
{
31+
std::cout << name << " : {";
32+
33+
bool first = true;
34+
35+
for (const auto& x : m) {
36+
if (first) {
37+
first = false;
38+
}
39+
else {
40+
std::cout << ", ";
41+
}
42+
std::cout << "[" << x.first << "," << x.second << "]";
43+
}
44+
std::cout << "}" << std::endl;
45+
}
46+
47+
int main()
48+
{
49+
std::flat_map<int, char> fm1 = {
50+
{10, 'a'},
51+
{20, 'b'},
52+
{30, 'c'}
53+
};
54+
55+
std::flat_map<int, char> fm2 = {
56+
{5, 'd'},
57+
{15, 'e'}
58+
};
59+
60+
// fm1とfm2を入れ替える
61+
std::swap(fm1, fm2);
62+
63+
print("fm1", fm1);
64+
print("fm2", fm2);
65+
}
66+
```
67+
* std::swap[color ff0000]
68+
69+
### 出力
70+
```
71+
fm1 : {[5,d], [15,e]}
72+
fm2 : {[10,a], [20,b], [30,c]}
73+
```
74+
75+
76+
## バージョン
77+
### 言語
78+
- C++23
79+
80+
### 処理系
81+
- [Clang](/implementation.md#clang): ??
82+
- [GCC](/implementation.md#gcc): ??
83+
- [Visual C++](/implementation.md#visual_cpp): ??

reference/flat_map/flat_multimap.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ namespace std {
138138
139139
| 名前 | 説明 | 対応バージョン |
140140
|------|------|----------------|
141-
| [`swap`](flat_multimap/swap_free.md.nolink) | 2つの`flat_multimap`オブジェクトを入れ替える | C++23 |
141+
| [`swap`](flat_multimap/swap_free.md) | 2つの`flat_multimap`オブジェクトを入れ替える | C++23 |
142142
143143
144144
## 推論補助
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# swap (非メンバ関数)
2+
* flat_map[meta header]
3+
* std[meta namespace]
4+
* function template[meta id-type]
5+
* cpp23[meta cpp]
6+
7+
```cpp
8+
namespace std {
9+
template <class Key, class T, class Compare, class KeyContainer class MappedContainer>
10+
void swap(flat_multimap<Key, T, Compare, KeyContainer MappedContainer>& x,
11+
flat_multimap<Key, T, Compare, KeyContainer MappedContainer>& y); // (1) C++23
12+
}
13+
```
14+
15+
## 概要
16+
2つの `flat_multimap` オブジェクトを入れ替える。
17+
18+
19+
## 効果
20+
`x.`[`swap`](swap.md)`(y)`
21+
22+
23+
## 例
24+
```cpp example
25+
#include <flat_map>
26+
#include <iostream>
27+
28+
template <class Map>
29+
void print(const char* name, const Map& m)
30+
{
31+
std::cout << name << " : {";
32+
33+
bool first = true;
34+
35+
for (const auto& x : m) {
36+
if (first) {
37+
first = false;
38+
}
39+
else {
40+
std::cout << ", ";
41+
}
42+
std::cout << "[" << x.first << "," << x.second << "]";
43+
}
44+
std::cout << "}" << std::endl;
45+
}
46+
47+
int main()
48+
{
49+
std::flat_multimap<int, char> fm1 = {
50+
{10, 'a'},
51+
{20, 'b'},
52+
{30, 'c'}
53+
};
54+
55+
std::flat_multimap<int, char> fm2 = {
56+
{5, 'd'},
57+
{15, 'e'}
58+
};
59+
60+
// fm1とfm2を入れ替える
61+
std::swap(fm1, fm2);
62+
63+
print("fm1", fm1);
64+
print("fm2", fm2);
65+
}
66+
```
67+
* std::swap[color ff0000]
68+
69+
### 出力
70+
```
71+
fm1 : {[5,d], [15,e]}
72+
fm2 : {[10,a], [20,b], [30,c]}
73+
```
74+
75+
76+
## バージョン
77+
### 言語
78+
- C++23
79+
80+
### 処理系
81+
- [Clang](/implementation.md#clang): ??
82+
- [GCC](/implementation.md#gcc): ??
83+
- [Visual C++](/implementation.md#visual_cpp): ??

0 commit comments

Comments
 (0)