The Wayback Machine - https://web.archive.org/web/20170827155508/http://ja.cppreference.com:80/w/cpp/algorithm/equal_range
名前空間
変種
操作

std::equal_range

提供: cppreference.com
< cpp‎ | algorithm

 
 
アルゴリズムライブラリ
機能します
Original:
Functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
シーケンス動作を非改変
Original:
Non-modifying sequence operations
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
シーケンス動作を変更する
Original:
Modifying sequence operations
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
操作を仕切る
Original:
Partitioning operations
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
(ソートされた範囲で)ソート操作
Original:
Sorting operations (on sorted ranges)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
バイナリ検索操作(ソート範囲で)
Original:
Binary search operations (on sorted ranges)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
binary_search
equal_range
(ソートされた範囲で)操作を設定します
Original:
Set operations (on sorted ranges)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
ヒープ操作
Original:
Heap operations
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
最小値/最大値操作
Original:
Minimum/maximum operations
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
数値演算
Original:
Numeric operations
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Cライブラリ
Original:
C library
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
 
Defined in header <algorithm>
template<class ForwardIt, class T >

std::pair<ForwardIt,ForwardIt>
    equal_range( ForwardIt first, ForwardIt last,

                 const T& value );
(1)
template<class ForwardIt, class T, class Compare >

std::pair<ForwardIt,ForwardIt>
    equal_range( ForwardIt first, ForwardIt last,

                 const T& value, Compare comp );
(2)
ソート範囲value[first, last)に等しいすべての要素を含む範囲を返します。範囲は2つのイテレータ、valueより小さくない'で、もう一つは、最初の要素大きいvalue以上を指す最初の要素を指す1で定義されています。 lower_bound()と.. - 最初の反復子は、あるいはupper_bound()、二回目で取得することができる
Original:
Returns a range containing all elements equal to value in the sorted range [first, last). The range is defined by two iterators, one pointing to the first element that is not less than value and another pointing to the first element greater than value. The first iterator may be alternatively obtained with lower_bound(), the second - with upper_bound().
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
最初のバージョンは、要素を比較するoperator<使用して、2番目のバージョンは、指定された比較関数compを使用しています.
Original:
The first version uses operator< to compare the elements, the second version uses the given comparison function comp.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

目次

[編集]パラメータ

first, last -
検討する要素の範囲
Original:
the range of elements to examine
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
value -
に要素を比較する値
Original:
value to compare the elements to
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
comp - 比較関数. 最初の値が二つ目の値より小さい 場合、 ​trueを返します.

比較関数のシグネチャは以下と同等でなければなりません.

 bool cmp(const Type1 &a, const Type2 &b);

シグネチャはconstを含まなくても構いませんが, 比較関数は渡されたオブジェクトを変更してはなりません.
The type Type1 must be such that an object of type T can be implicitly converted to Type1. The type Type2 must be such that an object of type ForwardIt can be dereferenced and then implicitly converted to Type2. ​

型の要件
-
ForwardItForwardIterator

の要求を満足しなければなりません。

[編集]値を返します

std::pair希望範囲を定義する反復子のペア、ではないvalue未満と最初の要素を指す第2の第1の要素を指す第一を含むvalueより大きい.
Original:
std::pair containing a pair of iterators defining the wanted range, the first pointing to the first element that is not less than value and the second pointing to the first element greater than value.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
どの要素value下回らないが存在しない場合は、lastは、最初の要素として返されます。同様に要素がない場合は大きいよりvaluelast番目の要素として返されます
Original:
If there are no elements not less than value, last is returned as the first element. Similarly if there are no elements greater than value, last is returned as the second element
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[編集]複雑性

firstlastとの間の距離の対数
Original:
Logarithmic in the distance between first and last
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[編集]可能な実装

First version
template<class ForwardIt, class T std::pair<ForwardIt,ForwardIt> equal_range(ForwardIt first, ForwardIt last, const T& value){returnstd::make_pair(std::lower_bound(first, last, value), std::upper_bound(first, last, value));}
Second version
template<class ForwardIt, class T, class Compare>std::pair<ForwardIt,ForwardIt> equal_range(ForwardIt first, ForwardIt last, const T& value, Compare comp);{returnstd::make_pair(std::lower_bound(first, last, value, comp), std::upper_bound(first, last, value, comp));}

[編集]

#include <algorithm>#include <vector>#include <iostream>   struct S {int number;char name;   S (int number, char name ): number ( number ), name ( name ){}   // only the number is relevant with this comparisonbool operator<(const S& s )const{return number < s.number;}};     int main(){std::vector<S> vec ={{1,'A'}, {2,'B'}, {2,'C'}, {2,'D'}, {3,'F'}, {4,'G'}};   S value (2, '?');   auto p = std::equal_range(vec.begin(),vec.end(),value);   for(auto i = p.first; i != p.second;++i )std::cout<< i->name <<' ';}

出力:

B C D

[編集]参照

最初の要素を指すイテレータを返す指定した値より小さくない
Original:
returns an iterator to the first element not less than the given value
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(関数テンプレート)[edit]
最初の要素を指すイテレータを返す特定の値より大きい
Original:
returns an iterator to the first element greater than a certain value
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(関数テンプレート)[edit]
要素が一定の範囲内に存在するかどうかを決定します
Original:
determines if an element exists in a certain range
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(関数テンプレート)[edit]
close