Namespaces
Variants

std::hive<T,Allocator>::hive

From cppreference.com
 
 
 
 
constexpr hive() noexcept(noexcept(Allocator()))
    : hive(Allocator()) {}
(1) (since C++26)
constexpr explicit hive( const Allocator& alloc ) noexcept;
(2) (since C++26)
constexpr explicit hive( std::hive_limits block_limits )
    : hive(block_limits, Allocator()) {}
(3) (since C++26)
constexpr hive( std::hive_limits block_limits, const Allocator& alloc );
(4) (since C++26)
explicit hive( size_type count, const Allocator& alloc = Allocator() );
(5) (since C++26)
hive( size_type count, std::hive_limits block_limits,
      const Allocator& alloc = Allocator() );
(6) (since C++26)
hive( size_type count, const T& value, const Allocator& alloc = Allocator() );
(7) (since C++26)
hive( size_type count, const T& value, std::hive_limits block_limits,
      const Allocator& alloc = Allocator() );
(8) (since C++26)
template< class InputIter >
hive( InputIter first, InputIter last, const Allocator& alloc = Allocator() );
(9) (since C++26)
template< class InputIter >
hive( InputIter first, InputIter last, std::hive_limits block_limits,
      const Allocator& alloc = Allocator() );
(10) (since C++26)
template< /*container-compatible-range*/<T> R >
hive( std::from_range_t, R&& rg, const Allocator& alloc = Allocator() );
(11) (since C++26)
template< /*container-compatible-range*/<T> R >
hive( std::from_range_t, R&& rg, std::hive_limits block_limits,
      const Allocator& alloc = Allocator() );
(12) (since C++26)
hive( const hive& other );
(13) (since C++26)
hive( hive&& other ) noexcept;
(14) (since C++26)
hive( const hive& other, const std::type_identity_t<Allocator>& alloc );
(15) (since C++26)
hive( hive&& other, const type_identity_t<Allocator>& alloc );
(16) (since C++26)
hive( std::initializer_list<T> ilist, const Allocator& alloc = Allocator() );
(17) (since C++26)
hive( std::initializer_list<T> ilist, std::hive_limits block_limits,
      const Allocator& alloc = Allocator() );
(18) (since C++26)

Constructs a new hive from a variety of data sources, optionally using a user supplied allocator alloc.

1,3) Constructs an empty hive with a default-constructed allocator.
2,4) Constructs an empty hive.
5,6) Constructs a hive with count default-inserted elements.
7,8) Constructs a hive with count copies of value.
9,10) Constructs a hive with the contents of the range [firstlast).
11,12) Constructs a hive with the contents of the range rg.
13,15) Constructs a hive with the contents of the other.
14) Moves each element block from other into *this. References, pointers and iterators that originally refer to elements in other remain valid, but refer to elements that are now in *this.
16) If alloc == other.get_allocator(), same as (14). Otherwise, moves each element from other into *this. References, pointers and iterators that originally refer to elements in other, as well as the end() iterator of other, are invalidated.
14,16) After the call, other.empty() is true. The relative order of the elements of *this is the same as that of the elements of other before the call.
17,18) Constructs a hive with the contents of the ilist.

2,4-12,15-18) Also uses the given allocator alloc.

3,4,6,8,10,12,18) Also initializes current-limits with block_limits.

13-16) Also initializes current-limits with other.current-limits.

Parameters

block_limits - block capacity limits
first, last - the pair of iterators defining the source range of elements to copy
alloc - allocator to use for all memory allocations of this container
count - the size of the container
value - the value to initialize elements of the container with
other - another container to be used as source to initialize the elements of the container with
ilist - initializer list to initialize the elements of the container with
rg - a container compatible range
Type requirements
-
Allocator must meet the requirements of DefaultConstructible in order to use overloads (1,3).
-
T must meet the requirements of DefaultInsertable in order to use overloads (5,6).
-
T must meet the requirements of CopyInsertable in order to use overloads (7,8,13,15,17,18).
-
T must meet the requirements of MoveInsertable in order to use overloads (16). (Only if
std::allocator_traits<Allocator>::is_always_equal::value is false).

Complexity

1-4) Constant.
5-8) Linear in count.
9,10) Linear in std::distance(first, last).
11,12) Linear in ranges::distance(rg).
13,14) Linear in other.size().
15) Constant.
16) Linear in other.size() if alloc != other.get_allocator(), otherwise constant.
17,18) Linear in ilist.size().

Exceptions

Calls to Allocator::allocate may throw.

Example

#include <algorithm>
#include <cassert>
#include <hive>
#include <initializer_list>
#include <print>
#include <ranges>
#include <string>

template <typename T>
void assert_equal(const auto& x, std::initializer_list<T>&& y)
{
    assert(std::ranges::equal(x, y));
}

int main()
{
    const std::size_t count{4};
    std::hive<int> h1(count); // (5) hive(size_type count)
    assert(h1.size() == count);

    const std::size_t value{42};
    std::hive<int> h2(count, value); // (7) hive(size_type count, const T& value)
    assert_equal(h2, {42, 42, 42, 42});

    std::hive<int> h3(h2.begin(), h2.end()); // (9) hive(InputIter first, InputIter last)
    assert_equal(h3, {42, 42, 42, 42});

    const auto list = {10, 11, 12};
    std::hive<int> h4(std::from_range, list); // (11) hive(from_range_t, R&&)
    assert_equal(h4, {10, 11, 12});

    std::hive<std::string> s1{"1", "2", "3"};
    auto h5 = std::hive(s1); // (13) hive(const hive& other)
    assert_equal(h5, {"1", "2", "3"});

    auto h6 = std::hive(std::move(h5)); // (14) hive(hive&& other)
    assert_equal(h6, {"1", "2", "3"});
    std::println("h5 = {} (after move out)", h5);

    std::hive<int> h7(list); // (18) hive(initializer_list<T> ilist)
    assert_equal(h7, {10, 11, 12});
}

Possible output:

h5 = [] (after move out)

See also

assigns values to the container
(public member function) [edit]
assigns values to the container
(public member function) [edit]