multimap::insert
map に要素または要素範囲を挿入します。
iterator insert(
const value_type& _Val
);
iterator insert(
iterator _Where,
const value_type& _Val
);
template<class InputIterator>
void insert(
InputIterator _First,
InputIterator _Last
);
template<class ValTy>
iterator insert(
ValTy&& _Val
);
template<class ValTy>
iterator insert(
const_iterator _Where,
ValTy&& _Val
);
パラメーター
パラメーター |
説明 |
_Val |
map が既にその要素をか、キーが同じで並べる要素をより汎用的に含まれている multimap に挿入する要素の値。 |
_Where |
挿入の正しいポイントの検索を開始する場所に関するヒント。 |
_First |
マップからコピーする最初の要素の位置。 |
_Last |
マップからコピーする最後の要素を越える位置だけ。 |
戻り値
insert のメンバー関数は新しい要素が multimap に挿入位置を指す反復子。
解説
要素の value_type は、要素の値がキー値と等しい最初の構成要素および要素のデータ値と等しい 2 番目のコンポーネントとの順序付けられたペアになるように、ペアです。
挿入は対数の時間ではなく、挿入のツールヒントのバージョンの経費償却定数時間で挿入位置がの _Whereする場合は、発生することがあります。
3 番目のメンバー関数は、指定されたセットの範囲 [_First、_Last) の反復子によってアドレス各要素に対応するマップに要素値のシーケンスを挿入します。
最後の 2 回のメンバー関数は、の最初の 2 と同様に機能し、挿入値の構築にただし、_Val が使用されます。
使用例
// multimap_insert.cpp
// compile with: /EHsc
#include <map>
#include <iostream>
#include <string>
int main( )
{
using namespace std;
multimap <int, int>::iterator m1_pIter, m2_pIter;
multimap <int, int> m1, m2;
typedef pair <int, int> Int_Pair;
m1.insert ( Int_Pair ( 1, 10 ) );
m1.insert ( Int_Pair ( 2, 20 ) );
m1.insert ( Int_Pair ( 3, 30 ) );
cout << "The original key values of m1 =";
for ( m1_pIter = m1.begin( ); m1_pIter != m1.end( ); m1_pIter++ )
cout << " " << m1_pIter -> first;
cout << "." << endl;
cout << "The original mapped values of m1 =";
for ( m1_pIter = m1.begin( ); m1_pIter != m1.end( ); m1_pIter++ )
cout << " " << m1_pIter -> second;
cout << "." << endl;
m1.insert ( Int_Pair ( 1, 10 ) );
// The hint version of insert
m1.insert( --m1.end( ), Int_Pair ( 4, 40 ) );
cout << "After the insertions, the key values of m1 =";
for ( m1_pIter = m1.begin( ); m1_pIter != m1.end( ); m1_pIter++ )
cout << " " << m1_pIter -> first;
cout << "," << endl;
cout << " and the mapped values of m1 =";
for ( m1_pIter = m1.begin( ); m1_pIter != m1.end( ); m1_pIter++ )
cout << " " << m1_pIter -> second;
cout << "." << endl;
m2.insert ( Int_Pair ( 10, 100 ) );
// The templatized version inserting a range
m2.insert( ++m1.begin( ), --m1.end( ) );
cout << "After the insertions, the key values of m2 =";
for ( m2_pIter = m2.begin( ); m2_pIter != m2.end( ); m2_pIter++ )
cout << " " << m2_pIter -> first;
cout << "," << endl;
cout << " and the mapped values of m2 =";
for ( m2_pIter = m2.begin( ); m2_pIter != m2.end( ); m2_pIter++ )
cout << " " << m2_pIter -> second;
cout << "." << endl;
// The templatized versions move constructing elements
multimap<int, string> m3, m4;
pair<int, string> is1(1, "a"), is2(2, "b");
m3.insert(move(is1));
cout << "After the move insertion, m3 contains:" << endl
<< " " << m3.begin()->first
<< " => " << m3.begin()->second
<< endl;
m4.insert(c4.begin(),move(is2));
cout << "After the move insertion, m4 contains:" << endl
<< " " << m4.begin()->first
<< " => " << m4.begin()->second
<< endl;
}
必要条件
ヘッダー: <map>
名前空間: std