![]() |
---|
此 API 已过时。另一种方法是 unordered_multiset Class。 |
插入元素或元素的范围。hash_multiset 中。
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
);
参数
Parameter |
描述 |
_Val |
要插入的元素的值设置为 hash_multiset,除非 hash_multiset,通常,已包含该元素或键相同地排序的元素。 |
_Where |
起始位置搜索正确位置插入。(插入在能够的常量时发生,而不是对数时,因此,如果插入点紧跟在 _Where。) |
_First |
从 hash_multiset 将复制的第一个元素的位置。 |
_Last |
在从 hash_multiset 将复制的最后一个元素之外。 |
返回值
前两个 插入 成员函数返回指向位置插入新元素的迭代器。
最后两个 插入 成员函数的行为与前两个相同,不同之处在于,它们将构造该插入的值。
备注
如果插入点紧跟在 _Where,在插入的提示版本中能够对常数的时间可能发生,而不是对数时间。
元素顺序值到 hash_multiset 的每个元素对应的第三成员函数插入由迭代器在范围解析的 [_First,_Last) 的指定 hash_multiset。
示例
// hash_multiset_insert.cpp
// compile with: /EHsc
#include <hash_set>
#include <iostream>
int main( )
{
using namespace std;
using namespace stdext;
hash_multiset <int>::iterator hms1_pIter, hms2_pIter;
hash_multiset <int, hash_compare <int, less<int> > > hms1, hms2;
hms1.insert( 10 );
hms1.insert( 20 );
hms1.insert( 30 );
hms1.insert( 40 );
cout << "The original hms1 =";
for ( hms1_pIter = hms1.begin( ); hms1_pIter != hms1.end( );
hms1_pIter++ )
cout << " " << *hms1_pIter;
cout << "." << endl;
hms1.insert( 20 );
hms1.insert( --hms1.end( ), 50 );
cout << "After the insertions, hms1 =";
for ( hms1_pIter = hms1.begin( ); hms1_pIter != hms1.end( );
hms1_pIter++ )
cout << " " << *hms1_pIter;
cout << "." << endl;
hms2.insert( 100 );
hms2.insert( ++hms1.begin( ), --hms1.end( ) );
cout << "hms2 =";
for ( hms2_pIter = hms2.begin( ); hms2_pIter != hms2.end( );
hms2_pIter++ )
cout << " " << *hms2_pIter;
cout << "." << endl;
// move construct an element
hash_multiset<string> hms3, hms4;
string str1("a"), str2("b");
hms3.insert(move(str1));
cout << "After the move insertion, hms3 contains "
<< *hms3.begin() << "." << endl;
hms4.insert(hms4.begin(), move(str1));
cout << "After the move insertion, hms4 contains "
<< *hms4.begin() << "." << endl;
}
要求
标头: <hash_set>
命名空间: stdext