Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d6e40dd
commit d91c1da
Showing
10 changed files
with
193 additions
and
4 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,74 @@ | ||
# contains | ||
* flat_map[meta header] | ||
* std[meta namespace] | ||
* flat_map[meta class] | ||
* function[meta id-type] | ||
* cpp23[meta cpp] | ||
|
||
```cpp | ||
bool contains(const key_type& x) const; // (1) C++23 | ||
|
||
template <class K> | ||
bool contains(const K& x) const; // (2) C++23 | ||
``` | ||
## 概要 | ||
指定されたキー`x`に一致する要素がコンテナに含まれているかを判定する。 | ||
- (1) : クラスのテンプレートパラメータ`key_type`型のキーを受け取る | ||
- (2) : `key_type`と比較可能な`K`型のキーを受け取る | ||
## 戻り値 | ||
以下と等価: | ||
```cpp | ||
return find(x) != end(); | ||
``` | ||
* find[link find.md] | ||
* end()[link end.md.nolink] | ||
|
||
|
||
## 計算量 | ||
対数時間 | ||
|
||
|
||
## 例 | ||
```cpp example | ||
#include <iostream> | ||
#include <flat_map> | ||
|
||
int main() | ||
{ | ||
std::flat_map<char, int> m = { | ||
{'a', 3}, | ||
{'b', 1}, | ||
{'c', 4} | ||
}; | ||
|
||
// キー'b'の要素が含まれているか | ||
if (m.contains('b')) { | ||
std::cout << "contain" << std::endl; | ||
} | ||
else { | ||
std::cout << "doesn't contain" << std::endl; | ||
} | ||
} | ||
``` | ||
* contains[color ff0000] | ||
|
||
### 出力 | ||
``` | ||
contain | ||
``` | ||
|
||
|
||
## バージョン | ||
### 言語 | ||
- C++23 | ||
|
||
### 処理系 | ||
- [Clang](/implementation.md#clang): ?? | ||
- [GCC](/implementation.md#gcc): ?? | ||
- [Visual C++](/implementation.md#visual_cpp): ?? |
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,99 @@ | ||
# count | ||
* flat_map[meta header] | ||
* std[meta namespace] | ||
* flat_map[meta class] | ||
* function[meta id-type] | ||
* cpp23[meta cpp] | ||
|
||
```cpp | ||
size_type count(const key_type& x) const; // (1) C++23 | ||
|
||
template <class K> | ||
size_type count(const K& x) const; // (2) C++23 | ||
``` | ||
## 概要 | ||
キー `x` を検索し、コンテナ内に見つかった要素の数を返す。`flat_map` コンテナはキーの重複を許さないため、この関数は実際には要素が見つかったときに 1 を、そうでないときに 0 を返す。 | ||
- (1) : クラスのテンプレートパラメータ`key_type`型のキーを受け取る | ||
- (2) : `key_type`と比較可能な`K`型のキーを受け取る | ||
## 戻り値 | ||
- (1) : `x`と等価なキーの要素が見つかった場合は1、そうでない場合は0を返す。 | ||
- (2) : `key_compare`型の関数オブジェクトを`c`、コンテナ内の各要素が持つキーを`k`として、キーが等価か判定する式`!c(k, x) && !c(x, k)`が`true`となる要素が見つかった場合は1、そうでない場合は0を返す。 | ||
## 計算量 | ||
``` | ||
log(b.size()) + b.count(k) | ||
``` | ||
* b.size()[link size.md] | ||
## 備考 | ||
- (2) : この関数がオーバーロード解決に参加する条件は、[`find()`](find.md)メンバ関数の備考欄を参照 | ||
- [`std::flat_multimap`](/reference/flat_map/flat_multimap.md.nolink)クラスとの共通インタフェースを使用する必要がなければ、この関数の代わりに[`contains()`](contains.md)メンバ関数を使用することを推奨する | ||
## 例 | ||
```cpp example | ||
#include <iostream> | ||
#include <flat_map> | ||
#include <string> | ||
int main() | ||
{ | ||
// (1) | ||
{ | ||
std::flat_map<std::string, int> fm = { | ||
{"Alice", 3}, | ||
{"Bob", 1}, | ||
{"Carol", 4} | ||
}; | ||
std::size_t n = fm.count("Bob"); | ||
if (n > 0) { // 見つかった | ||
std::cout << "found" << std::endl; | ||
} | ||
} | ||
// (2) | ||
{ | ||
std::flat_map<std::string, int, std::less<>> fm = { | ||
{"Alice", 3}, | ||
{"Bob", 1}, | ||
{"Carol", 4} | ||
}; | ||
// std::lessのvoidに対する特殊化を使用することで、 | ||
// 文字列リテラルをcount()関数の引数として渡した際に、 | ||
// std::string型の一時オブジェクトが生成されない。 | ||
std::size_t n = fm.count("Bob"); | ||
if (n > 0) { // 見つかった | ||
std::cout << "found" << std::endl; | ||
} | ||
} | ||
} | ||
``` | ||
* fm.count[color ff0000] | ||
* std::less[link /reference/functional/less.md] | ||
|
||
### 出力 | ||
``` | ||
found | ||
found | ||
``` | ||
|
||
## バージョン | ||
### 言語 | ||
- C++23 | ||
|
||
### 処理系 | ||
- [Clang](/implementation.md#clang): ?? | ||
- [GCC](/implementation.md#gcc): ?? | ||
- [Visual C++](/implementation.md#visual_cpp): ?? | ||
|
||
|
||
## 関連項目 | ||
- [`contains()`](contains.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 |
---|---|---|
|
@@ -104,5 +104,5 @@ int main() | |
|
||
|
||
## 関連項目 | ||
- [`contains()`](contains.md.nolink) | ||
- [`contains()`](contains.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
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
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
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