Skip to content

Commit

Permalink
add swap_free.md to flat_map (#1078)
Browse files Browse the repository at this point in the history
  • Loading branch information
suomesta committed Feb 9, 2025
1 parent 2a1427f commit f28cc8b
Show file tree
Hide file tree
Showing 4 changed files with 168 additions and 2 deletions.
2 changes: 1 addition & 1 deletion reference/flat_map/flat_map.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ namespace std {
| 名前 | 説明 | 対応バージョン |
|------|------|----------------|
| [`swap`](flat_map/swap_free.md.nolink) | 2つの`flat_map`オブジェクトを入れ替える | C++23 |
| [`swap`](flat_map/swap_free.md) | 2つの`flat_map`オブジェクトを入れ替える | C++23 |
## 推論補助
Expand Down
83 changes: 83 additions & 0 deletions reference/flat_map/flat_map/swap_free.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# swap (非メンバ関数)
* flat_map[meta header]
* std[meta namespace]
* function template[meta id-type]
* cpp23[meta cpp]

```cpp
namespace std {
template <class Key, class T, class Compare, class KeyContainer class MappedContainer>
void swap(flat_map<Key, T, Compare, KeyContainer MappedContainer>& x,
flat_map<Key, T, Compare, KeyContainer MappedContainer>& y); // (1) C++23
}
```
## 概要
2つの `flat_map` オブジェクトを入れ替える。
## 効果
`x.`[`swap`](swap.md)`(y)`
## 例
```cpp example
#include <flat_map>
#include <iostream>
template <class Map>
void print(const char* name, const Map& m)
{
std::cout << name << " : {";
bool first = true;
for (const auto& x : m) {
if (first) {
first = false;
}
else {
std::cout << ", ";
}
std::cout << "[" << x.first << "," << x.second << "]";
}
std::cout << "}" << std::endl;
}
int main()
{
std::flat_map<int, char> fm1 = {
{10, 'a'},
{20, 'b'},
{30, 'c'}
};
std::flat_map<int, char> fm2 = {
{5, 'd'},
{15, 'e'}
};
// fm1とfm2を入れ替える
std::swap(fm1, fm2);
print("fm1", fm1);
print("fm2", fm2);
}
```
* std::swap[color ff0000]

### 出力
```
fm1 : {[5,d], [15,e]}
fm2 : {[10,a], [20,b], [30,c]}
```


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

### 処理系
- [Clang](/implementation.md#clang): ??
- [GCC](/implementation.md#gcc): ??
- [Visual C++](/implementation.md#visual_cpp): ??
2 changes: 1 addition & 1 deletion reference/flat_map/flat_multimap.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ namespace std {
| 名前 | 説明 | 対応バージョン |
|------|------|----------------|
| [`swap`](flat_multimap/swap_free.md.nolink) | 2つの`flat_multimap`オブジェクトを入れ替える | C++23 |
| [`swap`](flat_multimap/swap_free.md) | 2つの`flat_multimap`オブジェクトを入れ替える | C++23 |
## 推論補助
Expand Down
83 changes: 83 additions & 0 deletions reference/flat_map/flat_multimap/swap_free.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# swap (非メンバ関数)
* flat_map[meta header]
* std[meta namespace]
* function template[meta id-type]
* cpp23[meta cpp]

```cpp
namespace std {
template <class Key, class T, class Compare, class KeyContainer class MappedContainer>
void swap(flat_multimap<Key, T, Compare, KeyContainer MappedContainer>& x,
flat_multimap<Key, T, Compare, KeyContainer MappedContainer>& y); // (1) C++23
}
```
## 概要
2つの `flat_multimap` オブジェクトを入れ替える。
## 効果
`x.`[`swap`](swap.md)`(y)`
## 例
```cpp example
#include <flat_map>
#include <iostream>
template <class Map>
void print(const char* name, const Map& m)
{
std::cout << name << " : {";
bool first = true;
for (const auto& x : m) {
if (first) {
first = false;
}
else {
std::cout << ", ";
}
std::cout << "[" << x.first << "," << x.second << "]";
}
std::cout << "}" << std::endl;
}
int main()
{
std::flat_multimap<int, char> fm1 = {
{10, 'a'},
{20, 'b'},
{30, 'c'}
};
std::flat_multimap<int, char> fm2 = {
{5, 'd'},
{15, 'e'}
};
// fm1とfm2を入れ替える
std::swap(fm1, fm2);
print("fm1", fm1);
print("fm2", fm2);
}
```
* std::swap[color ff0000]

### 出力
```
fm1 : {[5,d], [15,e]}
fm2 : {[10,a], [20,b], [30,c]}
```


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

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

0 comments on commit f28cc8b

Please sign in to comment.