名前空間
変種
操作

「cpp/container/multimap/equal range」の版間の差分

提供: cppreference.com
< cpp‎ | container‎ | multimap
(r2.7.3) (ロボットによる 追加: en:cpp/container/multimap/equal range)
(Translated from the English version using Google Translate)
1行: 1行:
{{title|equal_range}}
+
{{|equal_range}}
Syntax:
+
  
<syntaxhighlight lang="cpp">
+
[[:cpp/container/multimap/equal range]]
    #include <map>
+
    pair<iterator, iterator> equal_range( const key_type& key );
+
    pair<const_iterator, const_iterator> equal_range( const key_type& key ) const;
+
</syntaxhighlight>
+
 
+
equal_range()関数は、2つのイテレータを返します。一方は、キーを含む最初の要素を指し、もう一方はキーを含む最後の要素を指します。
+
 
+
たとえば、次のコードでは、不確定は入力ファイルの読み込み時に、マルチマップとstringとequal_range()関数を使っています。
+
 
+
<syntaxhighlight lang="cpp">
+
  multimap<string,pair<int,int> > input_config;
+
 
+
  // read configuration from file "input.conf" to input_config
+
  readConfigFile( input_config, "input.conf" );
+
 
+
  pair<multimap<string,pair<int,int> >::iterator,multimap<string,pair<int,int> >::iterator> ii;
+
  multimap<string,pair<int,int> >::iterator i;
+
 
+
  ii = input_config.equal_range("key");        // keyboard key-bindings
+
  // we can iterate over a range just like with begin() and end() 
+
  for( i = ii.first; i != ii.second; ++i ) {
+
    // add a key binding with this key and output
+
    bindkey(i->second.first, i->second.second);
+
  }
+
 
+
  ii = input_config.equal_range("joyb");        // joystick button key-bindings
+
  for( i = ii.first; i != ii.second; ++i ) {
+
    // add a key binding with this joystick button and output
+
    bindjoyb(i->second.first, i->second.second);
+
  }
+
 
+
</syntaxhighlight>
+
 
+
[[en:cpp/container/multimap/equal range]]
+

2012年10月26日 (金) 07:00時点における版

 
 
 
 
std::pair<iterator,iterator> equal_range( const Key& key );
std::pair<const_iterator,const_iterator> equal_range( const Key& key ) const;
コンテナにキーkey持つすべての要素を含む範囲を返します。 The range is defined by two iterators, one pointing to the first element that is not less than key and another pointing to the first element greater than key. The first iterator may be alternatively obtained with lower_bound(), the second - with upper_bound().
Original:
Returns a range containing all elements with key key in the container. The range is defined by two iterators, one pointing to the first element that is not less than key and another pointing to the first element greater than key. 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.

目次

パラメータ

key -
に要素を比較するためのキー値
Original:
key 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.

値を返します

std::pair containing a pair of iterators defining the wanted range: the first pointing to the first element that is not less than key and the second pointing to the first element greater than key.

If there are no elements not less than key, past-the-end (see end()) iterator is returned as the first element. Similarly if there are no elements greater than key, past-the-end iterator is returned as the second element.

複雑

Logarithmic in the size of the container.

も参照してください

指定されたキーを持つ要素を探します
(パブリックメンバ関数) [edit]
指定されたキーより大きい最初の要素を指すイテレータを返します
(パブリックメンバ関数) [edit]
指定されたキーより小さくない最初の要素を指すイテレータを返します
(パブリックメンバ関数) [edit]