std::flat_map<Key,T,Compare,KeyContainer,MappedContainer>:: equal_range
From cppreference.net
|
std::
pair
<
iterator, iterator
>
equal_range
(
const
Key
&
key
)
;
|
(1) |
(C++23以降)
(C++26以降 constexpr) |
|
std::
pair
<
const_iterator, const_iterator
>
equal_range ( const Key & key ) const ; |
(2) |
(C++23以降)
(C++26以降 constexpr) |
|
template
<
class
K
>
std:: pair < iterator, iterator > equal_range ( const K & x ) ; |
(3) |
(C++23以降)
(C++26以降 constexpr) |
|
template
<
class
K
>
std::
pair
<
const_iterator, const_iterator
>
|
(4) |
(C++23以降)
(C++26以降 constexpr) |
指定されたキーを持つすべての要素を含む範囲を返します。この範囲は2つのイテレータによって定義され、1つは指定されたキーより 小さくない 最初の要素を指し、もう1つは指定されたキーより大きい最初の要素を指します。
あるいは、最初のイテレータは lower_bound() で取得し、2番目のイテレータは upper_bound() で取得することもできます。
1,2)
キーを
key
と比較します。
3,4)
キーを値
x
と比較します。
このオーバーロードは、
Compare
が
transparent
である場合にのみ、オーバーロード解決に参加します。これにより、
Key
のインスタンスを構築せずにこの関数を呼び出すことが可能になります。
目次 |
パラメータ
| key | - | 要素と比較するキー値 |
| x | - |
Key
と比較可能な代替値
|
戻り値
std::pair 必要な範囲を定義する一組のイテレータを含む:
- 最初のイテレータは、指定されたキー以上である最初の要素を指し、そのような要素が存在しない場合は end ( ) を指します。
- 2番目のイテレータは、指定されたキーより大きい最初の要素を指し、そのような要素が存在しない場合は end ( ) を指します。
計算量
コンテナのサイズに対して対数的。
例
このコードを実行
#include <iostream> #include <flat_map> int main() { const std::flat_map<int, const char*> m { {0, "zero"}, {1, "one"}, {2, "two"} }; auto p = m.equal_range(1); for (auto& q = p.first; q != p.second; ++q) std::cout << "m[" << q->first << "] = " << q->second << '\n'; if (p.second == m.find(2)) std::cout << "end of equal_range (p.second) is one-past p.first\n"; else std::cout << "unexpected; p.second expected to be one-past p.first\n"; auto pp = m.equal_range(-1); if (pp.first == m.begin()) std::cout << "pp.first is iterator to first not-less than -1\n"; else std::cout << "unexpected pp.first\n"; if (pp.second == m.begin()) std::cout << "pp.second is iterator to first element greater-than -1\n"; else std::cout << "unexpected pp.second\n"; auto ppp = m.equal_range(3); if (ppp.first == m.end()) std::cout << "ppp.first is iterator to first not-less than 3\n"; else std::cout << "unexpected ppp.first\n"; if (ppp.second == m.end()) std::cout << "ppp.second is iterator to first element greater-than 3\n"; else std::cout << "unexpected ppp.second\n"; }
出力:
m[1] = one end of equal_range (p.second) is one-past p.first pp.first is iterator to first not-less than -1 pp.second is iterator to first element greater-than -1 ppp.first is iterator to first not-less than 3 ppp.second is iterator to first element greater-than 3
関連項目
|
特定のキーを持つ要素を検索
(public member function) |
|
|
コンテナが特定のキーを持つ要素を含むかどうかをチェック
(public member function) |
|
|
特定のキーにマッチする要素の数を返す
(public member function) |
|
|
指定されたキーより
大きい
最初の要素へのイテレータを返す
(public member function) |
|
|
指定されたキーより
小さくない
最初の要素へのイテレータを返す
(public member function) |
|
|
特定のキーにマッチする要素の範囲を返す
(function template) |