共用方式為


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來指定序列副本;第四到第八個建構函式使用 initializer_list 指定要複製的項目。 第九個建構函式會插入項目值序列[first, last)。

所有建構函式也會初始化數個已儲存之值。 如需複製建構函式,其值會從 Right 取得。 否則就是:

bucket最小數若為引數則為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

請參閱

參考

<unordered_set>

unordered_set 類別

其他資源

<unordered_set> 成員