[hive.cons]

# 23 Containers library [[containers]](./#containers)

## 23.3 Sequence containers [[sequences]](sequences#hive.cons)

### 23.3.9 Class template hive [[hive]](hive#cons)

#### 23.3.9.2 Constructors, copy, and assignment [hive.cons]

[ð](#lib:hive,constructor)

`constexpr explicit hive(const Allocator&) noexcept;
`

[1](#1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8139)

*Effects*: Constructs an empty hive, using the specified allocator[.](#1.sentence-1)

[2](#2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8143)

*Complexity*: Constant[.](#2.sentence-1)

[ð](#lib:hive,constructor_)

`constexpr hive(hive_limits block_limits, const Allocator&);
`

[3](#3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8154)

*Effects*: Constructs an empty hive, using the specified allocator[.](#3.sentence-1)

Initializes *current-limits* with block_limits[.](#3.sentence-2)

[4](#4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8159)

*Complexity*: Constant[.](#4.sentence-1)

[ð](#lib:hive,constructor__)

`explicit hive(size_type n, const Allocator& = Allocator());
hive(size_type n, hive_limits block_limits, const Allocator& = Allocator());
`

[5](#5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8171)

*Preconditions*: T is *Cpp17DefaultInsertable* into hive[.](#5.sentence-1)

[6](#6)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8175)

*Effects*: Constructs a hive with n default-inserted elements,
using the specified allocator[.](#6.sentence-1)

If the second overload is called,
also initializes *current-limits* with block_limits[.](#6.sentence-2)

[7](#7)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8182)

*Complexity*: Linear in n[.](#7.sentence-1)

[ð](#lib:hive,constructor___)

`hive(size_type n, const T& value, const Allocator& = Allocator());
hive(size_type n, const T& value, hive_limits block_limits, const Allocator& = Allocator());
`

[8](#8)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8194)

*Preconditions*: T is *Cpp17CopyInsertable* into hive[.](#8.sentence-1)

[9](#9)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8198)

*Effects*: Constructs a hive with n copies of value,
using the specified allocator[.](#9.sentence-1)

If the second overload is called,
also initializes *current-limits* with block_limits[.](#9.sentence-2)

[10](#10)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8205)

*Complexity*: Linear in n[.](#10.sentence-1)

[ð](#lib:hive,constructor____)

`template<class InputIterator>
  hive(InputIterator first, InputIterator last, const Allocator& = Allocator());
template<class InputIterator>
  hive(InputIterator first, InputIterator last, hive_limits block_limits,
       const Allocator& = Allocator());
`

[11](#11)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8220)

*Effects*: Constructs a hive equal to the range [first, last),
using the specified allocator[.](#11.sentence-1)

If the second overload is called,
also initializes *current-limits* with block_limits[.](#11.sentence-2)

[12](#12)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8227)

*Complexity*: Linear in distance(first, last)[.](#12.sentence-1)

[ð](#lib:hive,constructor_____)

`template<[container-compatible-range](container.intro.reqmts#concept:container-compatible-range "23.2.2.1 Introduction [container.intro.reqmts]")<T> R>
  hive(from_range_t, R&& rg, const Allocator& = Allocator());
template<[container-compatible-range](container.intro.reqmts#concept:container-compatible-range "23.2.2.1 Introduction [container.intro.reqmts]")<T> R>
  hive(from_range_t, R&& rg, hive_limits block_limits, const Allocator& = Allocator());
`

[13](#13)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8241)

*Effects*: Constructs a hive object with the elements of the range rg,
using the specified allocator[.](#13.sentence-1)

If the second overload is called,
also initializes *current-limits* with block_limits[.](#13.sentence-2)

[14](#14)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8248)

*Complexity*: Linear in ranges​::​distance(rg)[.](#14.sentence-1)

[ð](#lib:hive,constructor______)

`hive(const hive& x);
hive(const hive& x, const type_identity_t<Allocator>& alloc);
`

[15](#15)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8260)

*Preconditions*: T is *Cpp17CopyInsertable* into hive[.](#15.sentence-1)

[16](#16)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8264)

*Effects*: Constructs a hive object with the elements of x[.](#16.sentence-1)

If the second overload is called, uses alloc[.](#16.sentence-2)

Initializes *current-limits* with x.*current-limits*[.](#16.sentence-3)

[17](#17)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8270)

*Complexity*: Linear in x.size()[.](#17.sentence-1)

[ð](#lib:hive,constructor_______)

`hive(hive&& x) noexcept;
hive(hive&& x, const type_identity_t<Allocator>& alloc);
`

[18](#18)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8282)

*Preconditions*: For the second overload,
when allocator_traits<alloc>​::​is_always_equal​::​value is false,T meets the *Cpp17MoveInsertable* requirements[.](#18.sentence-1)

[19](#19)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8288)

*Effects*: When the first overload is called, or
the second overload is called andalloc == x.get_allocator() is true,*current-limits* is set to x.*current-limits* and
each element block is moved from x into *this[.](#19.sentence-1)

Pointers and references to the elements of x now refer to
those same elements but as members of *this[.](#19.sentence-2)

Iterators referring to the elements of x will continue to refer to their elements,
but they now behave as iterators into *this[.](#19.sentence-3)

If the second overload is called andalloc == x.get_allocator() is false,
each element in x is moved into *this[.](#19.sentence-4)

References, pointers and iterators referring to the elements of x, as well as the past-the-end iterator of x, are invalidated[.](#19.sentence-5)

[20](#20)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8306)

*Postconditions*: x.empty() is true[.](#20.sentence-1)

[21](#21)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8310)

*Complexity*: If the second overload is called andalloc == x.get_allocator() is false, linear in x.size()[.](#21.sentence-1)

Otherwise constant[.](#21.sentence-2)

[ð](#lib:hive,constructor________)

`hive(initializer_list<T> il, const Allocator& = Allocator());
hive(initializer_list<T> il, hive_limits block_limits, const Allocator& = Allocator());
`

[22](#22)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8324)

*Preconditions*: T is *Cpp17CopyInsertable* into hive[.](#22.sentence-1)

[23](#23)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8328)

*Effects*: Constructs a hive object with the elements of il,
using the specified allocator[.](#23.sentence-1)

If the second overload is called,
also initializes *current-limits* with block_limits[.](#23.sentence-2)

[24](#24)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8335)

*Complexity*: Linear in il.size()[.](#24.sentence-1)

[ð](#lib:operator=,hive)

`hive& operator=(const hive& x);
`

[25](#25)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8346)

*Preconditions*: T is *Cpp17CopyInsertable* into hive and*Cpp17CopyAssignable*[.](#25.sentence-1)

[26](#26)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8351)

*Effects*: All elements in *this are either copy-assigned to, or destroyed[.](#26.sentence-1)

All elements in x are copied into *this[.](#26.sentence-2)

[*Note [1](#note-1)*:

*current-limits* is unchanged[.](#26.sentence-3)

â *end note*]

[27](#27)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8359)

*Complexity*: Linear in size() + x.size()[.](#27.sentence-1)

[ð](#lib:operator=,hive_)

`hive& operator=(hive&& x)
  noexcept(allocator_traits<Allocator>::propagate_on_container_move_assignment::value ||
           allocator_traits<Allocator>::is_always_equal::value);
`

[28](#28)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8372)

*Preconditions*: When(allocator_traits<Allocator>::propagate_on_container_move_assignment::value || allocator_traits<Allocator>::is_always_equal::value) is false,T is *Cpp17MoveInsertable* into hive and*Cpp17MoveAssignable*[.](#28.sentence-1)

[29](#29)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8383)

*Effects*: Each element in *this is either move-assigned to, or destroyed[.](#29.sentence-1)

When(allocator_traits<Allocator>::propagate_on_container_move_assignment::value || get_allocator() == x.get_allocator()) is true,*current-limits* is set to x.*current-limits* and
each element block is moved from x into *this[.](#29.sentence-2)

Pointers and references to the elements of x now refer to those same elements but as members of *this[.](#29.sentence-3)

Iterators referring to the elements of x will continue to refer to their elements,
but they now behave as iterators into *this, not into x[.](#29.sentence-4)

When(allocator_traits<Allocator>::propagate_on_container_move_assignment::value || get_allocator() == x.get_allocator()) is false,
each element in x is moved into *this[.](#29.sentence-5)

References, pointers and iterators referring to the elements of x,
as well as the past-the-end iterator of x, are invalidated[.](#29.sentence-6)

[30](#30)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8410)

*Postconditions*: x.empty() is true[.](#30.sentence-1)

[31](#31)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8414)

*Complexity*: Linear in size()[.](#31.sentence-1)

If(allocator_traits<Allocator>::propagate_on_container_move_assignment::value || get_allocator() == x.get_allocator()) is false, also linear in x.size()[.](#31.sentence-2)
