std::unordered_set

cppreference.com

Example

print_set: (set) = {
    for set do (elem) {
        std::cout << "(elem)$ ";
    }
    std::cout << '\n';
}

main: () = {
    mySet: std::unordered_set = (2, 7, 1, 8, 2, 8); // creates a set of ints
    print_set(mySet);
 
    mySet.insert(5); // puts an element 5 in the set
    print_set(mySet);
 
    (iter:= mySet.find(5))
    if iter != mySet.end() {
        mySet.erase(iter); // removes an element pointed to by iter
    }
    print_set(mySet);
 
    mySet.erase(7); // removes an element 7
    print_set(mySet);
}

Possible output

8 1 7 2 
5 8 1 7 2 
8 1 7 2 
8 1 2 

Back to top

cpp2reference.com licensed under CC-BY-SA and GFDL.