-
Notifications
You must be signed in to change notification settings - Fork 162
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
flat_map : add value_compare, key_comp() and value_comp() (#1078)
- Loading branch information
Showing
4 changed files
with
193 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# key_comp | ||
* flat_map[meta header] | ||
* std[meta namespace] | ||
* flat_map[meta class] | ||
* function[meta id-type] | ||
* cpp23[meta cpp] | ||
|
||
```cpp | ||
key_compare key_comp() const; // C++23 | ||
``` | ||
|
||
|
||
## 概要 | ||
コンテナに関連づけられたキー比較用の関数オブジェクトを返す。このオブジェクトはコンテナ内の二つの要素のキー値を比較するために利用できる。 | ||
この比較オブジェクトはオブジェクトの構築時に与えられ、関数へのポインタでも関数オブジェクトでも良い。いずれの場合でも、これは同じ型の 2 つの引数をとり、[狭義の弱順序](/reference/algorithm.md#strict-weak-ordering)に従って一つ目の引数が二つ目の引数より前のときに `true` を返し、そうでないときに `false` を返す。 | ||
|
||
|
||
## 戻り値 | ||
比較オブジェクト。`key_compare` はメンバ型であり、テンプレートパラメータ `Compare` の別名として定義される。 | ||
|
||
|
||
## 計算量 | ||
定数時間。 | ||
|
||
|
||
## 例 | ||
```cpp example | ||
#include <flat_map> | ||
#include <iostream> | ||
|
||
int main() | ||
{ | ||
std::flat_map<int, char> m; | ||
std::flat_map<int, char>::key_compare comp = m.key_comp(); | ||
|
||
std::cout << comp(1, 2) << std::endl; | ||
std::cout << comp(3, 2) << std::endl; | ||
} | ||
``` | ||
* key_comp()[color ff0000] | ||
|
||
### 出力 | ||
``` | ||
1 | ||
0 | ||
``` | ||
|
||
|
||
## バージョン | ||
### 言語 | ||
- C++23 | ||
|
||
### 処理系 | ||
- [Clang](/implementation.md#clang): ?? | ||
- [GCC](/implementation.md#gcc): ?? | ||
- [ICC](/implementation.md#icc): ?? | ||
- [Visual C++](/implementation.md#visual_cpp): ?? | ||
|
||
|
||
## 関連項目 | ||
|
||
| 名前 | 説明 | | ||
|-------------------------------------|----------------------------------------------------------| | ||
| [`value_comp`](value_comp.md) | 要素比較用の関数オブジェクトを返す | | ||
| [`value_compare`](value_compare.md) | 要素値のキー部分で大小関係を判定する二項述語の型 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
# value_comp | ||
* flat_map[meta header] | ||
* std[meta namespace] | ||
* flat_map[meta class] | ||
* function[meta id-type] | ||
* cpp23[meta cpp] | ||
|
||
```cpp | ||
value_compare value_comp() const; // C++23 | ||
``` | ||
|
||
|
||
## 概要 | ||
コンテナに関連づけられた要素比較用の関数オブジェクトを返す。これはコンテナ内の二つの要素のキー部分を比較するために利用できる。 | ||
これは同じ型の 2 つの引数をとり、[狭義の弱順序](/reference/algorithm.md#strict-weak-ordering)に従って一つ目の引数が二つ目の引数の前になる場合に `true`、そうでない場合に `false` を返す。 | ||
|
||
|
||
## 戻り値 | ||
要素比較用の関数オブジェクト。 | ||
[`value_compare`](value_compare.md) はメンバ型である。`key_compare` とは異なり、単なる型の別名ではなく入れ子クラスである。 | ||
|
||
|
||
## 計算量 | ||
定数時間。 | ||
|
||
|
||
## 例 | ||
```cpp example | ||
#include <flat_map> | ||
#include <iostream> | ||
#include <utility> | ||
|
||
int main() | ||
{ | ||
std::flat_map<int, char> m; | ||
std::flat_map<int, char>::value_compare comp = m.value_comp(); | ||
|
||
auto p1 = std::make_pair(1, 'a'); | ||
auto p2 = std::make_pair(2, 'b'); | ||
auto p3 = std::make_pair(3, 'c'); | ||
|
||
std::cout << comp(p1, p2) << std::endl; | ||
std::cout << comp(p3, p2) << std::endl; | ||
} | ||
``` | ||
* value_comp()[color ff0000] | ||
* value_compare[link value_compare.md] | ||
|
||
### 出力 | ||
``` | ||
1 | ||
0 | ||
``` | ||
|
||
|
||
## バージョン | ||
### 言語 | ||
- C++23 | ||
|
||
### 処理系 | ||
- [Clang](/implementation.md#clang): ?? | ||
- [GCC](/implementation.md#gcc): ?? | ||
- [ICC](/implementation.md#icc): ?? | ||
- [Visual C++](/implementation.md#visual_cpp): ?? | ||
|
||
|
||
## 関連項目 | ||
|
||
| 名前 | 説明 | | ||
|-------------------------------------|----------------------------------------------------------| | ||
| [`key_comp`](key_comp.md) | キー比較用の関数オブジェクトを取得する | | ||
| [`value_compare`](value_compare.md) | 要素値のキー部分で大小関係を判定する二項述語の型 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# value_compare | ||
* flat_map[meta header] | ||
* std[meta namespace] | ||
* flat_map[meta class] | ||
* class[meta id-type] | ||
* cpp23[meta cpp] | ||
|
||
```cpp | ||
namespace std { | ||
class flat_map::value_compare; | ||
} | ||
``` | ||
## 概要 | ||
`value_compare` は `flat_map` の入れ子クラスで、`flat_map::value_type` 型のオブジェクトを比較する関数オブジェクト型である。 | ||
比較の基準は `flat_map::key_compare` と同様であるが、`flat_map::key_compare` の関数呼び出し演算子の引数型が `flat_map::key_type` であるのに対して、本クラスの関数呼び出し演算子の比較型は `flat_map::value_type` である点が異なっている。 | ||
なお、引数のうち [`flat_map`](../../flat_map.md)`::mapped_type` にあたる [`pair`](../../utility/pair.md) の `second` 部については、比較時には無視される。 | ||
## メンバ関数 | ||
| 名前 | 説明 | 対応バージョン | | ||
|-----------------------------------------------------------|--------------------|----------------| | ||
| [`operator()`](value_compare/op_call.md.nolink) | 関数呼び出し演算子 | | | ||
一般的な実装では、`key_compare` 型をメンバ変数で保持しており、その変数名を `comp` とすると、以下の動作となる。 | ||
```cpp | ||
bool operator()(const_reference x, const_reference y) const { | ||
return comp(x.first, y.first); | ||
} | ||
``` | ||
## 例 | ||
[`value_comp()`](value_comp.md) の例を参照。 | ||
## バージョン | ||
### 言語 | ||
- C++23 | ||
### 処理系 | ||
- [Clang](/implementation.md#clang): ?? | ||
- [GCC](/implementation.md#gcc): ?? | ||
- [ICC](/implementation.md#icc): ?? | ||
- [Visual C++](/implementation.md#visual_cpp): ?? | ||
## 関連項目 | ||
| 名前 | 説明 | | ||
|-------------------------------------|----------------------------------------------------------| | ||
| [`key_comp`](key_comp.md) | キー比較用の関数オブジェクトを取得する | | ||
| [`value_comp`](value_comp.md) | 要素比較用の関数オブジェクトを返す | |