Namespaces
Variants

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

From cppreference.com
 
 
 
 
void splice( hive& other );
(1) (since C++26)
void splice( hive&& other );
(2) (since C++26)
1,2) Transfers all elements from other into *this. The container other becomes empty after the operation.

No elements are copied or moved, only the internal pointers of the hive's element blocks are re-pointed. Reserved blocks in other are not transferred into *this.

No iterators or references become invalidated, the iterators to moved elements remain valid, but now refer into *this, not into other. If std::addressof(other) == this is false, invalidates the past-the-end iterator for both other and *this.

If an exception is thrown, there are no effects.

If std::addressof(other) == this is true, the behavior is erroneous and there are no effects.

If any of the following conditions is met, the behavior is undefined:

  • get_allocator() != other.get_allocator(),
  • *this and other refer to the same object.

Parameters

other - another container to transfer the content from

Complexity

1,2) Constant.

Exceptions

1,2) std::length_error if any of other's active element blocks are not within the bounds of capacity-limits, as well as any exceptions thrown by the allocator.

Example

#include <hive>
#include <print>

int main()
{
    std::hive<int> hotel{1, 2, 3}, motel{4, 5};

    std::println("Before splice: hotel = {}, motel = {}", hotel, motel);

    hotel.splice(motel);

    std::println("After splice: hotel = {}, motel = {}", hotel, motel);
}

Output:

Before splice: hotel = [1, 2, 3], motel = [4, 5]
After splice: hotel = [1, 2, 3, 4, 5], motel = []

See also

removes elements satisfying specific criteria
(public member function) [edit]
Morty Proxy This is a proxified and sanitized view of the page, visit original site.