unordered_set::unordered_set
构造容器对象。
unordered_set(
const unordered_set& Right
);
explicit unordered_set(
size_type bucket_count = N0,
const Hash& Hash = Hash(),
const Comp& Comp = Comp(),
const Allocator& Al = Alloc()
);
unordered_set(
unordered_set&& Right
);
unordered_set(
initializer_list<Type> IList
);
unordered_set(
initializer_list<Type> IList,
size_type bucket_count
);
unordered_set(
initializer_list<Type> IList,
size_type bucket_count,
const Hash& Hash
);
unordered_set(
initializer_list<Type> IList,
size_type bucket_count,
const Hash& Hash,
const Comp& Comp
);
unordered_set(
initializer_list<Type> IList,
size_type bucket_count,
const Hash& Hash,
const Comp& Comp,
const Allocator& Al
);
template<class InputIterator>
unordered_set(
InputIterator first,
InputIterator last,
size_type bucket_count = N0,
const Hash& Hash = Hash(),
const Comp& Comp = Comp(),
const Allocator& Al = Alloc());
参数
参数 |
说明 |
InputIterator |
迭代器类型。 |
Al |
存储的分配器对象。 |
Comp |
存储的比较函数对象。 |
Hash |
存储的哈希函数对象。 |
bucket_count |
存储桶的最小值。 |
Right |
复制的容器。 |
IList |
initializer_list 包含要复制的元素. |
备注
第一个构造函数通过Right指定了控制序列的副本。 第二个构造函数指定一个空控件序列。 第三个构造函数通过移动Right 来指定序列的副本。第四个到第八个构造函数使用初始化列表来指定拷贝副本。 第九个构造函数将值为[first, last)的元素插入序列
所有构造函数还初始化若干存储的值。 对于拷贝构造函数,值是从 Right 获取的。 否则:
如果存在,桶的最小数是参数bucket_count;否则它是在这里描述为实现定义的默认值N0。
如果存在,哈希函数对象是参数Hash;否则它是Hash()。
如果存在,比较函数对象是参数Comp;否则它是Comp()。
如果存在,分配器对象是参数Al;否则它是Alloc()。
示例
代码
/ std_tr1__unordered_set__unordered_set_construct.cpp
// compile with: /EHsc
#include <unordered_set>
#include <iostream>
using namespace std;
typedef unordered_set<char> Myset;
int main()
{
Myset c1;
c1.insert('a');
c1.insert('b');
c1.insert('c');
// display contents " [c] [b] [a]"
for (auto& c : c1){
cout << " [" << c << "]";
}
cout << endl;
Myset c2(8,
hash<char>(),
equal_to<char>(),
allocator<pair<const char, int> >());
c2.insert('d');
c2.insert('e');
c2.insert('f');
// display contents " [f] [e] [d]"
for (auto& c : c2){
cout << " [" << c << "]";
}
cout << endl;
Myset c3(c1.begin(),
c1.end(),
8,
hash<char>(),
equal_to<char>(),
allocator<pair<const char, int> >());
// display contents " [c] [b] [a]"
for (auto& c : c3){
cout << " [" << c << "]";
}
cout << endl;
Myset c4(move(c3));
// display contents " [c] [b] [a]"
for (auto& c : c4){
cout << " [" << c << "]";
}
cout << endl;
Myset c5{ { 'a', 'b', 'c' } };
for (auto& c : c5){
cout << " [" << c << "]";
}
cout << endl;
}
Output
[a] [b] [c]
[d] [e] [f]
[a] [b] [c]
[a] [b] [c]
要求
标头: <unordered_set>
命名空间: std