# inplace_vector and the new C++26 containers

> C++26 adds inplace_vector, a vector whose capacity is fixed and whose elements live inside the object; hive, a block-based container with stable addresses; and indirect and polymorphic, which give heap-allocated objects value semantics. optional becomes a range and gains a reference specialization, and span gets at().

- **Source:** C++ Atlas (https://cppatlas.com/topics/inplace-vector-and-new-containers)
- **Track:** C++26
- **Estimated reading time:** 14 minutes
- **ISO C++ clauses:** [inplace.vector] (https://eel.is/c++draft/inplace.vector), [inplace.vector.overview] (https://eel.is/c++draft/inplace.vector.overview), [inplace.vector.modifiers] (https://eel.is/c++draft/inplace.vector.modifiers), [hive] (https://eel.is/c++draft/hive), [hive.overview] (https://eel.is/c++draft/hive.overview), [hive.modifiers] (https://eel.is/c++draft/hive.modifiers), [indirect] (https://eel.is/c++draft/indirect), [polymorphic] (https://eel.is/c++draft/polymorphic), [optional.iterators] (https://eel.is/c++draft/optional.iterators), [optional.optional.ref] (https://eel.is/c++draft/optional.optional.ref), [span.elem] (https://eel.is/c++draft/span.elem), [container.reqmts] (https://eel.is/c++draft/container.reqmts)
- **cppreference links:** [std::inplace_vector](https://en.cppreference.com/w/cpp/container/inplace_vector), [std::inplace_vector::try_push_back](https://en.cppreference.com/w/cpp/container/inplace_vector/try_push_back), [std::span::at](https://en.cppreference.com/w/cpp/container/span/at), [std::optional](https://en.cppreference.com/w/cpp/utility/optional), [std::optional::begin](https://en.cppreference.com/w/cpp/utility/optional/begin)
- **Prerequisites:** sequence-containers, iterator-invalidation, optional-variant-any, smart-pointers, span-and-mdspan

## The one idea

Each new type in this topic answers one question: where does the object live, and what happens to it when you copy or move the thing that owns it?

An `inplace_vector<T, N>` keeps up to `N` elements inside itself, like an `array` with a size, so it never allocates. A `hive<T>` spreads its elements over separately allocated blocks and never moves one to make room, so pointers to elements stay valid. `indirect<T>` and `polymorphic<T>` put one object on the heap but copy it deeply, so a class can hold an incomplete or polymorphic member and still behave like a value.

This is C++26. The papers are P0843R14 for `inplace_vector` (2024), P0447R28 for `hive` and P3019R14 for `indirect` and `polymorphic` (both February 2025), P3168R2 for optional range support, P2988R12 for `optional<T&>`, and P2821R5 for `span::at`. National-body comments then changed `inplace_vector` in March 2026: P3981R2 made `try_push_back` return `optional<T&>`, and P4022R0 removed `try_append_range`. Everything here follows N5050, the final C++26 draft. Its international ballot closed in October 2026 and was reported as not approved, so check the status before you quote it as published ISO C++. GCC 16's libstdc++ implements everything here except `hive`, behind `-std=c++26`, and its `inplace_vector` is not yet fully constexpr. Clang 21's libc++ has none of these types.

> **Mental model.** `inplace_vector` is "storage inside, size varies". `hive` is "storage outside, addresses never move". `indirect` and `polymorphic` are "storage outside, but copies are deep". Pick by asking who owns the bytes and what a copy means.

## inplace_vector: capacity in the type

`inplace_vector<T, N>` is a contiguous sequence container. It supports almost everything `vector` does, except the front operations: there is no `push_front`, `pop_front`, `emplace_front` or `prepend_range`. Its storage is a member, so moving one is linear in the number of elements, like `array` and unlike `vector`. The same is true of `swap`.

`capacity()` and `max_size()` are `static constexpr` and return `N`. `reserve(n)` is static too. It does nothing, except that it throws `bad_alloc` when `n > N`. `shrink_to_fit()` does nothing at all.

The headline rule is how it reports overflow. Any member function that would make the size exceed `N` throws `std::bad_alloc`, even though no allocation was attempted. That includes constructors, `resize`, `insert` and `push_back`.

```cpp
#include <cstdio>
#include <inplace_vector>
#include <new>

int main() {
  std::inplace_vector<int, 3> v{1, 2, 3};
  try {
    v.push_back(4);                       // would make size 4 > 3
  } catch (const std::bad_alloc&) {
    std::puts("full");                    // printed; v is unchanged
  }
  try {
    std::inplace_vector<int, 3> w(10);    // the constructor also throws
  } catch (const std::bad_alloc&) {
    std::puts("too big");
  }
}
```

> **Standardese.** [inplace.vector.overview] says that any member function of `inplace_vector<T, N>` that would cause the size to exceed `N` throws an exception of type `bad_alloc`. `push_back` and `emplace_back` additionally promise that if an exception is thrown there are no effects on the container.

Because the elements never relocate, `push_back` and `emplace_back` leave existing pointers and references valid. Middle insertion and erasure still shift the later elements, as in `vector`.

## Three ways to append

Throwing is right when overflow is a bug. When overflow is an expected outcome, or when exceptions are not available, two other families exist:

- `try_push_back(x)` and `try_emplace_back(args...)` append if there is room and return `optional<T&>` referring to the new element. If the vector is full they do nothing and return `nullopt`. They throw only if constructing the element throws.
- `unchecked_push_back(x)` and `unchecked_emplace_back(args...)` have the precondition `size() < capacity()`. Breaking it is undefined behavior, so use them only after you have checked.

```cpp
#include <cstdio>
#include <inplace_vector>

int main() {
  std::inplace_vector<int, 2> v;
  for (int i = 0; i < 4; ++i) {
    if (auto r = v.try_push_back(i * 10))
      std::printf("stored %d\n", *r);     // prints 0 and 10
    else
      std::printf("dropped %d\n", i * 10); // prints 20 and 30
  }
  if (v.size() < v.capacity())
    v.unchecked_push_back(99);            // not reached: v is full
}
```

In a freestanding implementation, the throwing members are deleted, while the `try_` and `unchecked_` members remain available.

> **Pitfall.** Until March 2026 the draft had `try_push_back` return `T*`, with a null pointer for failure, and it also had `try_append_range`. Older articles, and the cppreference page for `try_push_back`, still show that design. The final C++26 text returns `optional<T&>`, and `try_append_range` is gone. GCC 16 already follows the final text, and it reports `__cpp_lib_inplace_vector` as `202603L`.

## Triviality and constexpr

`inplace_vector` passes triviality through from `T`. If `T` has a trivial copy constructor, so does `inplace_vector<T, N>`. The same goes for the move constructor. If `T` is trivially destructible, so is the vector, and then it also has trivial copy and move assignment when `T` does. So `inplace_vector<int, 8>` is trivially copyable and can be copied with `memcpy`. For `N == 0`, the specialization is empty and trivially copyable whatever `T` is.

```cpp
#include <inplace_vector>
#include <string>
#include <type_traits>

static_assert(std::is_trivially_copyable_v<std::inplace_vector<int, 8>>);
static_assert(std::is_empty_v<std::inplace_vector<std::string, 0>>);
static_assert(std::inplace_vector<std::string, 5>::capacity() == 5);
```

Every member is `constexpr`, and constant evaluation also handles the overflow exception, since C++26 allows exceptions there. P0843R14 limited constant evaluation to trivially copyable, trivially default-constructible element types. P3074R7 (trivial unions, February 2025) removed that limit, and `__cpp_lib_constexpr_inplace_vector` marks the change.

```cpp
#include <inplace_vector>
#include <new>

constexpr int overflow() {
  std::inplace_vector<int, 1> v{1};
  try { v.push_back(2); } catch (const std::bad_alloc&) { return 42; }
  return 0;
}
static_assert(overflow() == 42);
```

GCC 16 does not define `__cpp_lib_constexpr_inplace_vector`. Its `inplace_vector` works at compile time only when `T` is trivial, so a `constexpr` function that builds an `inplace_vector<std::string, 3>` fails to evaluate. The topic on constexpr in C++26 covers the language side of this.

## hive: stable addresses, unordered insertion

A `hive<T, Allocator>` stores elements in a chain of separately allocated **element blocks**. Erasing an element does not move any other element. The draft only says that erased slots are found and skipped by "unspecified techniques of constant time complexity". The reference implementation, plf::colony, keeps a **skipfield** in each block that records runs of erased slots, so iteration can jump over a run in one step. It also keeps a free list of erased slots, which later insertions reuse. Blocks that become empty are freed or kept as reserved blocks. Block sizes grow by an implementation-defined factor and can be bounded with `hive_limits`.

```text
block 0 (cap 4)      block 1 (cap 8)
[ a ][ - ][ c ][ d ] [ e ][ - ][ - ][ h ][ . ][ . ][ . ][ . ]
       ^ erased             ^ skip run of 2   ^ unused capacity
iteration: a c d e h  (no element ever moved)
```

The consequences are written into the interface:

- `insert` and `emplace` take no position. The container chooses where the element goes, and a hint argument is ignored. Both are constant time.
- Insertion invalidates only the past-the-end iterator. Erasure invalidates only iterators, pointers and references to the erased elements, and also `end()` if the last element goes.
- Iterators are bidirectional, but they also support `<` and `<=>`. There is no `operator[]`.
- `hive` has no `==` or `!=`, because two hives with the same elements may hold them in different orders.
- `sort`, `unique` and `splice` are members. `get_iterator(p)` turns an element pointer back into an iterator, in time linear in the number of blocks.
- `reserve` and `trim_capacity` never invalidate anything. `shrink_to_fit`, `reshape` and `sort` may move elements and invalidate everything.

`hive` suits workloads like game entities or particle systems: lots of insertion and erasure, frequent iteration, and other structures holding pointers into the container. If you only need fast erase and don't care about order, a `vector` with swap-and-pop is often simpler. `hive` earns its place when pointers into the container must survive.

GCC 16 does not ship `<hive>`, and neither does Clang 21's libc++, so nothing in this section could be compiled here. The statements above come from the N5050 text.

## indirect and polymorphic: heap objects with value semantics

`unique_ptr<T>` is a natural way to hold a large, incomplete or polymorphic member, but it makes the enclosing class move-only and makes `const` shallow. `indirect<T>` and `polymorphic<T>`, in `<memory>`, fix both problems. Copying one copies the owned object. A `const` wrapper gives only `const` access to the owned object. Neither has a null state in normal use. The default constructor allocates and value-initializes a `T`, and the converting constructors are `explicit`.

```cpp
#include <cstdio>
#include <memory>
#include <string>

struct Node;                                   // incomplete is fine here
struct Tree { std::indirect<Node> child; };

struct Doc {
  std::indirect<std::string> text{std::string("draft")};
  void touch() const {
    // text->append("!");                      // error: *text is const here
  }
};

int main() {
  Doc a;
  Doc b = a;                                   // deep copy: a new string
  b.text->append(" v2");
  std::printf("%s / %s\n", a.text->c_str(), b.text->c_str()); // draft / draft v2
}
struct Node { int v = 0; };
```

`indirect<T>` always owns exactly a `T`. It compares and hashes by value: `==` and `<=>` compare the owned objects, and comparison with a plain `T` works too. `polymorphic<T>` may own any type `U` derived from `T`, which must be copy-constructible. Copying it copies the object as its dynamic type, so there is no slicing. It has no comparison operators and no hash.

Both types have a **valueless** state, reachable only by moving from the object. `valueless_after_move()` reports it. Dereferencing a valueless object is undefined behavior. You may assign to it or destroy it.

> **Pitfall.** After `auto q = std::move(p);`, an `indirect` is guaranteed valueless. A `polymorphic` is not. Its move constructor may either take ownership of the owned object, which leaves `p` valueless, or construct a new object from it as an rvalue, which leaves `p` holding a moved-from object. That latitude allows a small-buffer implementation. GCC 16's plain move constructor always takes ownership, but portable code must not rely on either result.

## Smaller changes: optional and span

**optional is a range** (P3168R2). `optional<T>` has `begin()` and `end()` with contiguous iterators, and `ranges::enable_view` is specialized as true, so an optional is a view of zero or one elements. A range-for over an empty optional does nothing, and an optional composes with views. Formatting optionals as ranges is explicitly disabled. Initializing or destroying the contained value invalidates the iterators.

```cpp
#include <cstdio>
#include <optional>
#include <ranges>

int main() {
  std::optional<int> o = 4;
  for (int x : o | std::views::transform([](int x) { return x * 10; }))
    std::printf("%d\n", x);                    // prints 40
  o.reset();
  for (int x : o) std::printf("%d\n", x);      // prints nothing
}
```

**optional<T&>** (P2988R12) is now a partial specialization. It holds a pointer, it is trivially copyable, and it is a borrowed range. Assignment **rebinds**: `r = b` makes `r` refer to `b`, and it never assigns through to the old referent. Construction that would bind to a temporary is deleted, so `std::optional<const int&> r = 42;` is ill-formed. `value_or` returns a value, not a reference. `optional<T&&>` is not allowed.

```cpp
#include <cstdio>
#include <optional>

int main() {
  int a = 1, b = 2;
  std::optional<int&> r = a;
  r = b;                                       // rebinds; a is untouched
  *r = 3;
  std::printf("%d %d\n", a, b);                // 1 3
}
```

**span::at** (P2821R5) throws `out_of_range` for a bad index, like the containers' `at`. `operator[]`, `front` and `back` instead have hardened preconditions, which are checked only in a hardened implementation.

P2447R6 had added a `span` constructor from `initializer_list` for C++26. In March 2026, P4144R1 removed it again, because it changed the meaning of existing code such as `span<const bool>{ptr, n}`, which picked the new constructor instead of the pointer-and-size one. It is not in N5050. GCC 16 does not provide it, but Clang 21's libc++ still does.

## What to remember

- `inplace_vector<T, N>` stores its elements inside the object and never allocates. Overflow throws `bad_alloc`, `try_push_back` returns `optional<T&>`, and `unchecked_push_back` makes overflow undefined behavior.
- `capacity`, `max_size` and `reserve` are static. Move and swap are linear, as for `array`.
- Triviality passes through from `T`, and `inplace_vector<T, 0>` is empty and trivially copyable. The draft makes everything constexpr; GCC 16 manages that only for trivial `T`.
- `hive` gives constant-time insert and erase with stable addresses. The container chooses where elements go, iterators are bidirectional, and there is no `==`. GCC 16 does not ship it.
- `indirect` and `polymorphic` are deep-copying, const-propagating owners. They become valueless only after a move. A moved-from `polymorphic` may or may not be valueless.
- `optional<T>` is a view of zero or one elements. `optional<T&>` rebinds on assignment and refuses temporaries.
- `span::at` throws. The `span` constructor from `initializer_list` was added and then removed before C++26 was finished.

## Concept Map Outline

- **C++26 containers:** inplace_vector, hive, indirect and polymorphic, plus optional as a range, optional<T&> and span::at.
  - **inplace_vector:** A contiguous sequence container with capacity N fixed in the type and elements stored inside the object (P0843R14).
    - **Overflow throws bad_alloc:** Any member that would make size exceed N throws bad_alloc; push_back then has no effects.
    - **try_push_back:** Returns optional<T&>, or nullopt when full, since P3981R2. Older sources show a T* return.
    - **unchecked_push_back:** Precondition size() < capacity(); violating it is undefined behavior.
    - **Static capacity:** capacity, max_size and reserve are static; reserve(n > N) throws bad_alloc. Move and swap are linear.
    - **Triviality passes through:** Trivial copy, move and destruction of T give the same for the vector; N == 0 is empty and trivially copyable.
    - **constexpr:** Fully constexpr in the draft since P3074R7; GCC 16 supports constant evaluation only for trivial T.
  - **hive:** Block-based container with constant-time insert and erase that never moves surviving elements (P0447R28).
    - **Unordered insertion:** insert and emplace take no position; the hint is ignored and erased slots may be reused.
    - **Stable addresses:** Insertion invalidates only end(); erasure invalidates only the erased elements.
    - **Skipfield:** The reference implementation skips runs of erased slots in O(1); the draft only says the technique is unspecified.
    - **Interface limits:** Bidirectional iterators with <=>, no operator[], no ==; sort, unique, splice and get_iterator are members.
    - **Not in GCC 16:** Neither libstdc++ 16 nor libc++ 21 ships <hive>.
  - **indirect:** Owns one heap-allocated T, copies it deeply and propagates const (P3019R14).
    - **Never null normally:** The default constructor allocates a value-initialized T; converting constructors are explicit.
    - **Value comparison:** == and <=> compare the owned objects, and work against a plain T; hash is provided.
    - **Incomplete T:** T may be incomplete where the member is declared, so it suits recursive types and pimpl.
  - **polymorphic:** Owns an object of any type derived from T and copies it as its dynamic type, so nothing is sliced.
    - **Derived and copyable:** The owned type must derive from T and be copy-constructible; there are no comparisons or hash.
    - **Valueless after move:** Moved-from indirect is valueless; moved-from polymorphic may or may not be, which permits small buffers.
  - **optional and span:** Smaller C++26 library changes to existing vocabulary types.
    - **optional is a view:** begin and end give zero or one elements with contiguous iterators (P3168R2).
    - **optional<T&>:** Holds a pointer, rebinds on assignment, refuses temporaries, and is a borrowed range (P2988R12).
    - **span::at:** Throws out_of_range for a bad index (P2821R5); operator[] has only a hardened precondition.
    - **No initializer_list span:** P2447R6 added it, and P4144R1 removed it in March 2026; libc++ 21 still ships it.

## Standardese Quiz Questions

### Question 1 [warmup] ([inplace.vector.overview], [inplace.vector.modifiers])

Under the C++26 draft, what does this program print?

```cpp
#include <cstdio>
#include <inplace_vector>
#include <new>

int main() {
  std::inplace_vector<int, 2> v{1, 2};
  if (auto r = v.try_push_back(3))
    std::puts("appended");
  else
    std::puts("full");
  try {
    v.push_back(3);
  } catch (const std::bad_alloc&) {
    std::puts("bad_alloc");
  }
  std::printf("%zu\n", v.size());
}
```

A. `appended`, `bad_alloc`, `3`
B. `full`, `bad_alloc`, `2`
C. `full`, then `std::length_error` escapes `main` and `std::terminate` is called
D. `full`, then undefined behavior, because `push_back` on a full `inplace_vector` has a precondition

**Answer (B):** `full`, `bad_alloc`, `2`

**Why:** `try_push_back` on a full vector has no effects and returns `nullopt`, so `full` is printed. `push_back` on a full `inplace_vector` throws `std::bad_alloc`, even though nothing was allocated, and it has no effects on the container, so the size is still 2. The precondition answer describes `unchecked_push_back`, which is the member whose overflow is undefined behavior. `length_error` is what `vector` throws when a request exceeds `max_size()`, but it is not what `inplace_vector` uses for exceeding its capacity.

### Question 2 [warmup] ([optional.iterators], [optional.syn])

In C++26, what does this program print?

```cpp
#include <cstdio>
#include <optional>
#include <ranges>

int main() {
  std::optional<int> o = 4;
  int sum = 0;
  for (int x : o | std::views::transform([](int x) { return x * 10; }))
    sum += x;
  o.reset();
  for (int x : o)
    sum += x;
  std::printf("%d\n", sum);
}
```

A. `40`
B. `44`
C. Nothing: it is ill-formed, because `optional` is not a range
D. Undefined behavior, because the second loop iterates an empty optional

**Answer (A):** `40`

**Why:** Since P3168R2, `optional<T>` has `begin()` and `end()`, and `ranges::enable_view` is true for it, so it is a view of zero or one elements that composes with range adaptors. The first loop sees one element, 4, transformed to 40. After `reset()`, `begin() == end()`, so the second loop runs zero times, which is well-defined. The ill-formed answer was correct in C++23.

### Question 3 [warmup] ([indirect.ctor], [indirect.relops])

In C++26, what does this program print?

```cpp
#include <cstdio>
#include <memory>
#include <string>

int main() {
  std::indirect<std::string> a(std::string("hi"));
  std::indirect<std::string> b = a;
  b->append("!");
  std::printf("%s %s %d\n", a->c_str(), b->c_str(), a == b);
}
```

A. `hi! hi! 1`
B. `hi hi! 1`
C. `hi hi! 0`
D. Nothing: `indirect` is move-only, so the copy is ill-formed

**Answer (C):** `hi hi! 0`

**Why:** Copying an `indirect` allocates a new owned object and copy-constructs it from `*a`, so `b` owns a separate string, and appending to it leaves `a` alone. `==` between two `indirect` objects compares the owned values, not the pointers, and "hi" differs from "hi!", so it yields false. The first option describes `shared_ptr`-like shallow sharing. The move-only answer describes `unique_ptr`, which is exactly what `indirect` was designed to replace for value-like members.

### Question 4 [tricky] ([optional.optional.ref], [optional.ref.ctor], [optional.ref.assign])

In C++26, what does this program print?

```cpp
#include <cstdio>
#include <optional>

int main() {
  int a = 1, b = 2;
  std::optional<int&> r = a;
  r = b;
  *r = 3;
  std::printf("%d %d\n", a, b);
}
```

A. `2 3`: the assignment writes `b` through to `a`, and `*r` still refers to `a`
B. `1 3`
C. `3 2`
D. Nothing: `optional<int&>` is ill-formed

**Answer (B):** `1 3`

**Why:** `optional<T&>` (P2988R12) holds a pointer, and its assignment rebinds rather than assigning through. `r = b` converts `b` to an `optional<int&>` and copy-assigns that pointer, so afterwards `r` refers to `b`, so `*r = 3` changes `b` and leaves `a` as 1. The first option is the assign-through semantic that was debated for years and rejected, because it would make an engaged and a disengaged optional behave differently on assignment. `optional<int&>` was ill-formed before C++26, but it is valid now.

### Question 5 [tricky] ([indirect.obs], [indirect.ctor])

In C++26, is this program well-formed?

```cpp
#include <memory>

struct Counter {
  std::indirect<int> n{0};
  void bump() const { ++*n; }
};

int main() {
  Counter c;
  c.bump();
}
```

A. Well-formed: `const` applies to the wrapper, not to the owned `int`, as with `unique_ptr`
B. Ill-formed: `std::indirect<int>` cannot be initialized with `{0}`
C. Well-formed, but undefined behavior, because it modifies an object through a const path
D. Ill-formed: in a `const` member, `*n` is a `const int&`

**Answer (D):** Ill-formed: in a `const` member, `*n` is a `const int&`

**Why:** `indirect` propagates const. Its `operator*() const` returns `const T&`, so inside a `const` member function `*n` is a `const int` lvalue, and incrementing it is ill-formed. That is the key difference from `unique_ptr<int>`, where `const` stops at the pointer and the first option would be correct. The `{0}` initializer is fine, because the `explicit` converting constructor is allowed in direct-list-initialization.

### Question 6 [tricky] ([optional.ref.ctor], [class.temporary])

In C++26, is this program well-formed?

```cpp
#include <optional>

int main() {
  std::optional<const int&> r = 42;
  (void)r;
}
```

A. Well-formed: the temporary's lifetime is extended to match `r`, as with `const int& r = 42;`
B. Well-formed, but `r` dangles at the end of the statement, so any later use is undefined behavior
C. Ill-formed: the converting constructor is defined as deleted, because it would bind to a temporary
D. Ill-formed: `optional` cannot hold a reference to `const`

**Answer (C):** Ill-formed: the converting constructor is defined as deleted, because it would bind to a temporary

**Why:** The constructor `optional<T&>(U&&)` is defined as deleted when `reference_constructs_from_temporary_v<T&, U>` is true, and binding `const int&` to the prvalue 42 creates a temporary. Lifetime extension applies only to a reference bound directly in a declaration. A reference bound inside a constructor call would dangle, which is the bug the second option describes and the deleted constructor prevents. References to `const` are allowed; `optional<const int&> r = x;` for an `int x` is fine.

### Question 7 [standardese] ([polymorphic.ctor], [indirect.ctor], [polymorphic.general])

`Shape` is a polymorphic base class and `Circle` derives from it. What does the C++26 draft guarantee about `p.valueless_after_move()` after the last line?

```cpp
#include <memory>

struct Shape { virtual ~Shape() = default; };
struct Circle : Shape { double r = 1; };

int main() {
  std::polymorphic<Shape> p(Circle{});
  std::polymorphic<Shape> q = std::move(p);
  (void)q;
}
```

A. It is `true`, as it is for `indirect`
B. It is `false`: `p` still owns a moved-from `Circle`
C. Nothing: it may be `true` or `false`
D. The question is moot, because calling any member on a moved-from `polymorphic` is undefined behavior

**Answer (C):** Nothing: it may be `true` or `false`

**Why:** The move constructor of `polymorphic` says that `*this` either takes ownership of the owned object of `other`, or owns an object of the same type constructed from it as an rvalue. It has no postcondition about `other`, unlike `indirect`'s move constructor, which promises that `other` is valueless. The latitude allows an implementation to store small objects inline. Calling `valueless_after_move()` is always allowed, so the last option is wrong. GCC 16 happens to take ownership, which gives `true`, but that is not guaranteed.

### Question 8 [standardese] ([hive.capacity], [hive.modifiers], [hive.overview])

`h` is a `std::hive<int>` with many elements, and `p` points to one of them. According to the C++26 draft, which call may invalidate `p` even though that element is not erased?

A. `h.insert(7)`
B. `h.erase(it)`, where `it` refers to a different element
C. `h.reserve(h.capacity() * 2)`
D. `h.shrink_to_fit()`
E. `h.trim_capacity()`

**Answer (D):** `h.shrink_to_fit()`

**Why:** `shrink_to_fit` may reallocate elements, and if it does, all references, pointers and iterators into the hive are invalidated and the element order may change. Insertion invalidates only the past-the-end iterator, and erasure invalidates only what refers to the erased elements, which is the whole point of `hive`. `reserve` and `trim_capacity` only add or free reserved blocks, and the draft says they leave every reference, pointer and iterator valid. `sort` and `reshape` can also invalidate, but they are not offered here.
