Files
cppdraft_translate/cppdraft/hive/operations.md
2025-10-25 03:02:53 +03:00

6.3 KiB

[hive.operations]

23 Containers library [containers]

23.3 Sequence containers [sequences]

23.3.9 Class template hive [hive]

23.3.9.5 Operations [hive.operations]

1

#

In this subclause, arguments for a template parameter named Predicate or BinaryPredicate shall meet the corresponding requirements in [algorithms.requirements].

The semantics of i + n and i - n, where i is an iterator into the hive and n is an integer, are the same as those of next(i, n) and prev(i, n), respectively.

For sort, the definitions and requirements in [alg.sorting] apply.

🔗

void splice(hive& x); void splice(hive&& x);

2

#

Preconditions: get_allocator() == x.get_allocator() is true.

3

#

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

Otherwise, inserts the contents of x into *this andx becomes empty.

Pointers and references to the moved elements of x now refer to those same elements but as members of *this.

Iterators referring to the moved elements continue to refer to their elements, but they now behave as iterators into *this, not into x.

4

#

Throws: length_error if any of x's active blocks are not within the bounds of current-limits.

5

#

Complexity: Linear in the sum of all element blocks in x plus all element blocks in *this.

6

#

Remarks: Reserved blocks in x are not transferred into *this.

If addressof(x) == this is false, invalidates the past-the-end iterator for both x and *this.

🔗

template<class BinaryPredicate = equal_to<T>> size_type unique(BinaryPredicate binary_pred = BinaryPredicate());

7

#

Preconditions: binary_pred is an equivalence relation.

8

#

Effects: Erases all but the first element from every consecutive group of equivalent elements.

That is, for a nonempty hive, erases all elements referred to by the iterator i in the range [begin() + 1, end()) for which binary_pred(*i, *(i - 1)) is true.

9

#

Returns: The number of elements erased.

10

#

Throws: Nothing unless an exception is thrown by the predicate.

11

#

Complexity: If empty() is false, exactly size() - 1 applications of the corresponding predicate, otherwise no applications of the predicate.

12

#

Remarks: Invalidates references, pointers, and iterators referring to the erased elements.

If the last element in *this is erased, also invalidates the past-the-end iterator.

🔗

template<class Compare = less<T>> void sort(Compare comp = Compare());

13

#

Preconditions: T is Cpp17MoveInsertable into hive,Cpp17MoveAssignable, and Cpp17Swappable.

14

#

Effects: Sorts *this according to the comp function object.

If an exception is thrown, the order of the elements in *this is unspecified.

15

#

Complexity: O(NlogN) comparisons, where N is size().

16

#

Remarks: May allocate.

References, pointers, and iterators referring to elements in *this, as well as the past-the-end iterator, may be invalidated.

[Note 1:

Not required to be stable[algorithm.stable].

— end note]

🔗

iterator get_iterator(const_pointer p) noexcept; const_iterator get_iterator(const_pointer p) const noexcept;

17

#

Preconditions: p points to an element in *this.

18

#

Returns: An iterator or const_iterator pointing to the same element as p.

19

#

Complexity: Linear in the number of active blocks in *this.