名前空間
変種
操作

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

提供: cppreference.com
< cpp‎ | container‎ | multimap
(Import from dokuwiki)
 
 
(3人の利用者による、間の6版が非表示)
1行: 1行:
{{title|equal_range}}
+
{{|}}
Syntax:
+
  
<syntaxhighlight lang="cpp">
+
cpp/
    #include <map>
+
cppmultimap
    pair<iterator, iterator> equal_range( const key_type& key );
+
//multimap
    pair<const_iterator, const_iterator> equal_range( const key_type& key ) const;
+
://
</syntaxhighlight>
+
//range
 
+
//
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>
+

2018年3月16日 (金) 06:27時点における最新版