unordered_map::unordered_map
建構容器物件。
unordered_map(
const unordered_map& right);
explicit unordered_map(
size_type nbuckets = N0,
const Hash& hfn = Hash(),
const Pred& comp = Pred(),
const Alloc& al = Alloc());
template<class InIt>
unordered_map(
InIt first, InIt last,
size_type nbuckets = N0,
const Hash& hfn = Hash(),
const Pred& comp = Pred(),
const Alloc& al = Alloc());
unordered_map(
unordered_map&& right);
參數
參數 |
描述 |
InIt |
Iterator 型別。 |
al |
要儲存的配置器物件。 |
comp |
要儲存的比較函式物件。 |
hfn |
要儲存的雜湊函式物件。 |
nbuckets |
使用最少數目的雜湊桶中。 |
right |
要複製的容器。 |
備註
第一個建構函式會指定一份由控制序列right。第二個建構函式指定空的受控制的序列。第三個建構函式插入項目值的順序[first, last)。第四個建構函式會指定一份順序移動right。
所有的建構函式也會初始化數個儲存的值。複製建構函式,這些值取自right。否則就是:
雜湊桶的最小數目是引數nbuckets,如果有的話。 否則它是預設值所描述的實作定義的值視為N0。
雜湊函式物件是引數hfn,如果有的話。 否則就會是Hash()。
比較函式物件是引數comp,如果有的話。 否則就會是Pred()。
配置器的物件是引數al,如果有的話。 否則,它就是Alloc()。
範例
// std_tr1__unordered_map__unordered_map_construct.cpp
// compile with: /EHsc
#include <unordered_map>
#include <iostream>
typedef std::unordered_map<char, int> Mymap;
int main()
{
Mymap c1;
c1.insert(Mymap::value_type('a', 1));
c1.insert(Mymap::value_type('b', 2));
c1.insert(Mymap::value_type('c', 3));
// display contents " [c 3] [b 2] [a 1]"
for (Mymap::const_iterator it = c1.begin();
it != c1.end(); ++it)
std::cout << " [" << it->first << ", " << it->second << "]";
std::cout << std::endl;
Mymap c2(8,
std::tr1::hash<char>(),
std::equal_to<char>(),
std::allocator<std::pair<const char, int> >());
c2.insert(Mymap::value_type('d', 4));
c2.insert(Mymap::value_type('e', 5));
c2.insert(Mymap::value_type('f', 6));
// display contents " [f 6] [e 5] [d 4]"
for (Mymap::const_iterator it = c2.begin();
it != c2.end(); ++it)
std::cout << " [" << it->first << ", " << it->second << "]";
std::cout << std::endl;
Mymap c3(c1.begin(),
c1.end(),
8,
std::tr1::hash<char>(),
std::equal_to<char>(),
std::allocator<std::pair<const char, int> >());
// display contents " [c 3] [b 2] [a 1]"
for (Mymap::const_iterator it = c3.begin();
it != c3.end(); ++it)
std::cout << " [" << it->first << ", " << it->second << "]";
std::cout << std::endl;
Mymap c4(std::move(c3));
// display contents " [c 3] [b 2] [a 1]"
for (Mymap::const_iterator it = c4.begin();
it != c4.end(); ++it)
std::cout << " [" << it->first << ", " << it->second << "]";
std::cout << std::endl;
return (0);
}
需求
標頭: <unordered_map>
Namespace: 標準