◐ Shell
clean mode source ↗

std::hive - cppreference.com

From cppreference.com

Defined in header <hive>

template<
    class T,
    class Allocator = std::allocator<T>
> class hive;
(1) (since C++26)
namespace pmr {
    template<class T>
    using hive = std::hive<T, std::pmr::polymorphic_allocator<T>>;
}
(2) (since C++26)

1) std::hive is a sequence container that provides constant-time insertion and erasure operations.

The hive automatically manages its storage in multiple memory blocks (element blocks). Insertion position is unspecified, so the container can reuse the memory locations of erased elements.

When active blocks (element blocks that contain elements) become empty, they can be either deallocated or become reserved blocks.

Reserved blocks become active blocks when they are reused to store elements. A user can create additional reserved blocks by calling reserve().

Erasure and iteration both have constant‑time complexity.

The capacity of each active block grows by an implementation‑defined factor (e.g., by 1.69). Both users and implementations can limit the minimum and maximum element capacities of element blocks.

A std::hive conforms to the requirements of Container, with the exception of operators == and !=. A std::hive also meets the requirements of ReversibleContainer, of AllocatorAwareContainer, and some of the requirements of SequenceContainer.

Template parameters

T - The type of the elements.
The requirements that are imposed on the elements depend on the actual operations performed on the container. Generally, it is required that element type is a complete type and meets the requirements of Erasable, but many member functions impose stricter requirements.

[edit]

Allocator - An allocator that is used to acquire/release memory and to construct/destroy the elements in that memory. The type must meet the requirements of Allocator. The program is ill-formed if Allocator::value_type is not the same as T.[edit]

Member types

Member type Definition
value_type T[edit]
allocator_type Allocator[edit]
pointer std::allocator_traits<Allocator>::pointer[edit]
const_pointer std::allocator_traits<Allocator>::const_pointer[edit]
reference value_type&[edit]
const_reference const value_type&[edit]
size_type implementation-defined[edit]
difference_type implementation-defined[edit]
iterator implementation-defined LegacyBidirectionalIterator to value_type[edit]
const_iterator implementation-defined LegacyBidirectionalIterator to const value_type[edit]
reverse_iterator std::reverse_iterator<iterator>[edit]
const_reverse_iterator std::reverse_iterator<const_iterator>[edit]

Data members

Member Description
hive_limits current-limits (private) current block capacity limits
(exposition-only member object*)

Member functions

constructs the hive
(public member function) [edit]
destructs the hive
(public member function) [edit]
assigns values to the container
(public member function) [edit]
assigns values to the container
(public member function) [edit]
assigns a range of values to the container
(public member function) [edit]
returns the associated allocator
(public member function) [edit]
Iterators
returns an iterator to the beginning
(public member function) [edit]
returns an iterator to the end
(public member function) [edit]
returns a reverse iterator to the beginning
(public member function) [edit]
returns a reverse iterator to the end
(public member function) [edit]
Capacity
checks whether the container is empty
(public member function) [edit]
returns the number of elements
(public member function) [edit]
returns the maximum possible number of elements
(public member function) [edit]
returns the number of elements that can be held in currently allocated storage
(public member function) [edit]
reserves storage
(public member function) [edit]
reduces memory usage by freeing unused memory
(public member function) [edit]
deallocates reserved blocks and reduces capacity accordingly
(public member function) [edit]
returns current block capacity limits
(public member function) [edit]
returns block capacity default limits
(public member function) [edit]
returns block capacity hard limits
(public member function) [edit]
checks if given capacity limits are met
(public member function) [edit]
reallocates active blocks so they are within block limits
(public member function) [edit]
Modifiers
constructs element in-place
(public member function) [edit]
constructs elements in-place using a hint
(public member function) [edit]
inserts elements
(public member function) [edit]
inserts a range of elements
(public member function) [edit]
erases elements
(public member function) [edit]
swaps the contents
(public member function) [edit]
clears the contents
(public member function) [edit]
Operations
moves elements from another hive
(public member function) [edit]
removes consecutive duplicate elements
(public member function) [edit]
sorts the elements
(public member function) [edit]
returns an iterator pointing to the same element as given pointer
(public member function) [edit]

Non-member functions

Helper classes

layout information about block capacity limits in std::hive
(class) [edit]

Notes

Feature-test macro Value Std Feature
__cpp_lib_hive 202502L (C++26) std::hive

Example

See also

External links