共用方式為


unordered_multiset::unordered_multiset

建構一個容器物件。

unordered_multiset(
    const unordered_multiset& Right
);
explicit unordered_multiset(
    size_type Bucket_count = N0,
    const Hash& Hash = Hash(),
    const Comp& Comp = Comp(),
    const Allocator& Al = Alloc()
);
unordered_multiset(
    unordered_multiset&& Right
);
unordered_set(
    initializer_list<Type> IList
);
unordered_set(
    initializer_list<Typ > 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 Key& Key
);
unordered_set(
    initializer_list<Type> IList, 
    size_type Bucket_count, 
    const Hash& Hash, 
    const Key& Key, 
    const Allocator& Al
);
template<class InputIterator>
    unordered_multiset(
        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 控制的序列複本。 第二個建構函式會指定一個空的控制順序。 第三個建構函式會插入項目值序列[First, Last)。 第四個建構函式以移動 Right來指定序列的複本。

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

儲存桶最小數若為引數則為 Bucket_count;否則其為所述的預設值,即由實作環境所定義的值 N0。

雜湊函式物件若是引數則為 Hash;否則為 Hash()。

比對函式物件若是引數則為 Comp;否則為 Comp()。

配置器物件若是引數則為 Al;否則會是 Alloc()。

範例 

程式碼

/ std_tr1__unordered_set__unordered_multiset_construct.cpp 
// compile with: /EHsc 
#include <unordered_set> 
#include <iostream> 

using namespace std;

typedef unordered_multiset<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{ { 'g', 'h' } };
    for (auto& c : c5) {
        cout << " [" << c << "]";
    }
    cout << endl;
}
// std_tr1__unordered_set__unordered_multiset_construct.cpp 
// compile with: /EHsc 
#include <unordered_set> 
#include <iostream> 
 
typedef std::unordered_multiset<char> Myset; 
int main() 
    { 
    Myset c1; 
 
    c1.insert('a'); 
    c1.insert('b'); 
    c1.insert('c'); 
 
// display contents " [c] [b] [a]" 
    for (Myset::const_iterator it = c1.begin(); 
        it != c1.end(); ++it) 
        std::cout << " [" << *it << "]"; 
    std::cout << std::endl; 
 
    Myset c2(8, 
        std::hash<char>(), 
        std::equal_to<char>(), 
        std::allocator<std::pair<const char, int> >()); 
 
    c2.insert('d'); 
    c2.insert('e'); 
    c2.insert('f'); 
 
// display contents " [f] [e] [d]" 
    for (Myset::const_iterator it = c2.begin(); 
        it != c2.end(); ++it) 
        std::cout << " [" << *it << "]"; 
    std::cout << std::endl; 
 
    Myset c3(c1.begin(), 
        c1.end(), 
        8, 
        std::hash<char>(), 
        std::equal_to<char>(), 
        std::allocator<std::pair<const char, int> >()); 
 
// display contents " [c] [b] [a]" 
    for (Myset::const_iterator it = c3.begin(); 
        it != c3.end(); ++it) 
        std::cout << " [" << *it << "]"; 
    std::cout << std::endl; 
 
    Myset c4(std::move(c3));

// display contents " [c] [b] [a]" 
    for (Myset::const_iterator it = c3.begin(); 
        it != c3.end(); ++it) 
        std::cout << " [" << *it << "]"; 
    std::cout << std::endl; 

    return (0); 
    } 
 

Output

[a] [b] [c]
 [d] [e] [f]
 [a] [b] [c]
 [a] [b] [c]
 [g] [h]

需求

標頭: <unordered_set>

命名空間: std

請參閱

參考

<unordered_set>

unordered_multiset 類別

其他資源

<unordered_set> 成員