xte::array<T>::shrink()

Defined in header <xte/data/array.hpp>


Definition

constexpr void shrink() & noexcept(false) requires(/* See below */);
Reallocates to a capacity equal to the number of stored elements. If .capacity() is not greater than .size(), this has no effect. If allocation fails, the object remains unchanged. Requires that T is constructible from itself through std::move_if_noexcept().



Example

xte::array array = { 1, 2, 3 };
std::println("{}", array.capacity());
array.shrink();
std::println("{}", array.capacity());
Possible output:
16
3
[View in Compiler Explorer]