Skip to content

Commit 1854555

Browse files
committed
flat_map : add value_compare, key_comp() and value_comp() (#1078)
1 parent c00bf89 commit 1854555

File tree

4 files changed

+193
-3
lines changed

4 files changed

+193
-3
lines changed

reference/flat_map/flat_map.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ namespace std {
8787
8888
| 名前 | 説明 | 対応バージョン |
8989
|-------------------------------------|----------------------------------------|----------------|
90-
| [`key_comp`](flat_map/key_comp.md.nolink) | キー比較用の関数オブジェクトを取得する | C++23 |
91-
| [`value_comp`](flat_map/value_comp.md.nolink) | 要素比較用の関数オブジェクトを取得する | C++23 |
90+
| [`key_comp`](flat_map/key_comp.md) | キー比較用の関数オブジェクトを取得する | C++23 |
91+
| [`value_comp`](flat_map/value_comp.md) | 要素比較用の関数オブジェクトを取得する | C++23 |
9292
| [`keys`](flat_map/keys.md.nolink) | キーのコンテナを取得する | C++23 |
9393
| [`values`](flat_map/values.md.nolink) | 値のコンテナを取得する | C++23 |
9494
@@ -101,7 +101,7 @@ namespace std {
101101
| `mapped_type` | 値の型。テンプレートパラメータ `T` | C++23 |
102102
| `value_type` | 要素の型。[`std::pair`](/reference/utility/pair.md)`<key_type, mapped_type>` | C++23 |
103103
| `key_compare` | キー値の大小関係を判定する二項述語の型。テンプレートパラメータ `Compare` | C++23 |
104-
| [`value_compare`](flat_map/value_compare.md.nolink) | 要素値のキー部分で大小関係を判定する二項述語の型。入れ子クラス | C++23 |
104+
| [`value_compare`](flat_map/value_compare.md) | 要素値のキー部分で大小関係を判定する二項述語の型。入れ子クラス | C++23 |
105105
| `reference` | 要素への参照型。[`std::pair`](/reference/utility/pair.md)`<const key_type&, mapped_type&>` | C++23 |
106106
| `const_reference` | 要素への`const`参照型。[`std::pair`](/reference/utility/pair.md)`<const key_type&, const mapped_type&>` | C++23 |
107107
| `size_type` | 要素数を表す符号なし整数型 [`size_t`](/reference/cstddef/size_t.md) | C++23 |
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# key_comp
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+
key_compare key_comp() const; // C++23
10+
```
11+
12+
13+
## 概要
14+
コンテナに関連づけられたキー比較用の関数オブジェクトを返す。このオブジェクトはコンテナ内の二つの要素のキー値を比較するために利用できる。
15+
この比較オブジェクトはオブジェクトの構築時に与えられ、関数へのポインタでも関数オブジェクトでも良い。いずれの場合でも、これは同じ型の 2 つの引数をとり、[狭義の弱順序](/reference/algorithm.md#strict-weak-ordering)に従って一つ目の引数が二つ目の引数より前のときに `true` を返し、そうでないときに `false` を返す。
16+
17+
18+
## 戻り値
19+
比較オブジェクト。`key_compare` はメンバ型であり、テンプレートパラメータ `Compare` の別名として定義される。
20+
21+
22+
## 計算量
23+
定数時間。
24+
25+
26+
##
27+
```cpp example
28+
#include <flat_map>
29+
#include <iostream>
30+
31+
int main()
32+
{
33+
std::flat_map<int, char> m;
34+
std::flat_map<int, char>::key_compare comp = m.key_comp();
35+
36+
std::cout << comp(1, 2) << std::endl;
37+
std::cout << comp(3, 2) << std::endl;
38+
}
39+
```
40+
* key_comp()[color ff0000]
41+
42+
### 出力
43+
```
44+
1
45+
0
46+
```
47+
48+
49+
## バージョン
50+
### 言語
51+
- C++23
52+
53+
### 処理系
54+
- [Clang](/implementation.md#clang): ??
55+
- [GCC](/implementation.md#gcc): ??
56+
- [ICC](/implementation.md#icc): ??
57+
- [Visual C++](/implementation.md#visual_cpp): ??
58+
59+
60+
## 関連項目
61+
62+
| 名前 | 説明 |
63+
|-------------------------------------|----------------------------------------------------------|
64+
| [`value_comp`](value_comp.md) | 要素比較用の関数オブジェクトを返す |
65+
| [`value_compare`](value_compare.md) | 要素値のキー部分で大小関係を判定する二項述語の型 |
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# value_comp
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+
value_compare value_comp() const; // C++23
10+
```
11+
12+
13+
## 概要
14+
コンテナに関連づけられた要素比較用の関数オブジェクトを返す。これはコンテナ内の二つの要素のキー部分を比較するために利用できる。
15+
これは同じ型の 2 つの引数をとり、[狭義の弱順序](/reference/algorithm.md#strict-weak-ordering)に従って一つ目の引数が二つ目の引数の前になる場合に `true`、そうでない場合に `false` を返す。
16+
17+
18+
## 戻り値
19+
要素比較用の関数オブジェクト。
20+
[`value_compare`](value_compare.md) はメンバ型である。`key_compare` とは異なり、単なる型の別名ではなく入れ子クラスである。
21+
22+
23+
## 計算量
24+
定数時間。
25+
26+
27+
##
28+
```cpp example
29+
#include <flat_map>
30+
#include <iostream>
31+
#include <utility>
32+
33+
int main()
34+
{
35+
std::flat_map<int, char> m;
36+
std::flat_map<int, char>::value_compare comp = m.value_comp();
37+
38+
auto p1 = std::make_pair(1, 'a');
39+
auto p2 = std::make_pair(2, 'b');
40+
auto p3 = std::make_pair(3, 'c');
41+
42+
std::cout << comp(p1, p2) << std::endl;
43+
std::cout << comp(p3, p2) << std::endl;
44+
}
45+
```
46+
* value_comp()[color ff0000]
47+
* value_compare[link value_compare.md]
48+
49+
### 出力
50+
```
51+
1
52+
0
53+
```
54+
55+
56+
## バージョン
57+
### 言語
58+
- C++23
59+
60+
### 処理系
61+
- [Clang](/implementation.md#clang): ??
62+
- [GCC](/implementation.md#gcc): ??
63+
- [ICC](/implementation.md#icc): ??
64+
- [Visual C++](/implementation.md#visual_cpp): ??
65+
66+
67+
## 関連項目
68+
69+
| 名前 | 説明 |
70+
|-------------------------------------|----------------------------------------------------------|
71+
| [`key_comp`](key_comp.md) | キー比較用の関数オブジェクトを取得する |
72+
| [`value_compare`](value_compare.md) | 要素値のキー部分で大小関係を判定する二項述語の型 |
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# value_compare
2+
* flat_map[meta header]
3+
* std[meta namespace]
4+
* flat_map[meta class]
5+
* class[meta id-type]
6+
* cpp23[meta cpp]
7+
8+
```cpp
9+
namespace std {
10+
class flat_map::value_compare;
11+
}
12+
```
13+
14+
## 概要
15+
`value_compare` は `flat_map` の入れ子クラスで、`flat_map::value_type` 型のオブジェクトを比較する関数オブジェクト型である。
16+
比較の基準は `flat_map::key_compare` と同様であるが、`flat_map::key_compare` の関数呼び出し演算子の引数型が `flat_map::key_type` であるのに対して、本クラスの関数呼び出し演算子の比較型は `flat_map::value_type` である点が異なっている。
17+
なお、引数のうち [`flat_map`](../../flat_map.md)`::mapped_type` にあたる [`pair`](../../utility/pair.md) の `second` 部については、比較時には無視される。
18+
19+
20+
## メンバ関数
21+
| 名前 | 説明 | 対応バージョン |
22+
|-----------------------------------------------------------|--------------------|----------------|
23+
| [`operator()`](value_compare/op_call.md.nolink) | 関数呼び出し演算子 | |
24+
25+
一般的な実装では、`key_compare` 型をメンバ変数で保持しており、その変数名を `comp` とすると、以下の動作となる。
26+
```cpp
27+
bool operator()(const_reference x, const_reference y) const {
28+
return comp(x.first, y.first);
29+
}
30+
```
31+
32+
33+
## 例
34+
[`value_comp()`](value_comp.md) の例を参照。
35+
36+
37+
## バージョン
38+
### 言語
39+
- C++23
40+
41+
### 処理系
42+
- [Clang](/implementation.md#clang): ??
43+
- [GCC](/implementation.md#gcc): ??
44+
- [ICC](/implementation.md#icc): ??
45+
- [Visual C++](/implementation.md#visual_cpp): ??
46+
47+
48+
## 関連項目
49+
50+
| 名前 | 説明 |
51+
|-------------------------------------|----------------------------------------------------------|
52+
| [`key_comp`](key_comp.md) | キー比較用の関数オブジェクトを取得する |
53+
| [`value_comp`](value_comp.md) | 要素比較用の関数オブジェクトを返す |

0 commit comments

Comments
 (0)