Compartir a través de


unordered_set::unordered_set

Constructs a container object.

unordered_set(
    const unordered_set& right);
explicit unordered_set(
    size_type nbuckets = N0,
    const Hash& hfn = Hash(),
    const Pred& comp = Pred(),
    const Alloc& al = Alloc());
template<class InIt>
    unordered_set(
    InIt first, InIt last,
    size_type nbuckets = N0,
    const Hash& hfn = Hash(),
    const Pred& comp = Pred(),
    const Alloc& al = Alloc());
unordered_set(
    unordered_set&& right);

Parameters

Parameter

Description

InIt

The iterator type.

al

The allocator object to store.

comp

The comparison function object to store.

hfn

The hash function object to store.

nbuckets

The minimum number of buckets.

right

The container to copy.

Remarks

The first constructor specifies a copy of the sequence controlled by right. The second constructor specifies an empty controlled sequence. The third constructor inserts the sequence of element values [first, last). The fourth constructor specifies a copy of the sequence by moving right.

All constructors also initialize several stored values. For the copy constructor, the values are obtained from right. Otherwise:

the minimum number of buckets is the argument nbuckets, if present; otherwise it is a default value described here as the implementation-defined value N0.

the hash function object is the argument hfn, if present; otherwise it is Hash().

the comparison function object is the argument comp, if present; otherwise it is Pred().

the allocator object is the argument al, if present; otherwise, it is Alloc().

Example 

Code

// std_tr1__unordered_set__unordered_set_construct.cpp 
// compile with: /EHsc 
#include <unordered_set> 
#include <iostream> 
 
typedef std::unordered_set<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

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

Requirements

Header: <unordered_set>

Namespace: std

See Also

Reference

<unordered_set>

unordered_set Class

Other Resources

<unordered_set> Members