std::unordered_set<Key,Hash,KeyEqual,Allocator>::extract (3) - Linux Man Pages

std::unordered_set<Key,Hash,KeyEqual,Allocator>::extract: std::unordered_set<Key,Hash,KeyEqual,Allocator>::extract


std::unordered_set<Key,Hash,KeyEqual,Allocator>::extract - std::unordered_set<Key,Hash,KeyEqual,Allocator>::extract


node_type extract( const_iterator position ); (1) (since C++17)
node_type extract( const key_type& x ); (2) (since C++17)

1) Unlinks the node that contains the element pointed to by position and returns a node_handle that owns it
2) If the container has an element with key equivalent to x, unlinks the node that contains that element from the container and returns a node_handle that owns it. Otherwise, returns an empty node handle.
In either case, no elements are copied or moved, only the internal pointers of the container nodes are repointed

Extracting a node invalidates only the iterators to the extracted element, and preserves the relative order of the elements that are not erased. Pointers and references to the extracted element remain valid, but cannot be used while element is owned by a node handle: they become usable if the element is inserted into a container.


position - a valid iterator into this container
x - a key to identify the node to be extracted

Return value

A node_handle that owns the extracted element, or empty node handle in case the element is not found in overload (2)


1,2) Average case O(1), worst case O(a.size()).


extract is the only way to take a move-only object out of a set

  set<move_only_type> s;
  move_only_type mot = move(s.extract(s.begin()).value());


 This section is incomplete
 Reason: no example

See also

merge splices nodes from another container
        (public member function)
        inserts elements
        or nodes
insert (since C++17)
        (public member function)
        erases elements
erase (public member function)