JH-Toolkit v1.4.1
An engineering-oriented C++20 toolkit with duck-typed concepts, static design, async coroutines, and semantic containers — header-only, RTTI-free, and concurrency-friendly.
Loading...
Searching...
No Matches
jh::runtime_arr< T, Alloc > Class Template Referencefinal

A move-only, fixed-capacity array with runtime-determined length and RAII-based ownership. More...

#include <jh/core/runtime_arr.h>

Classes

struct  uninitialized_t

Public Types

using value_type = T
 Value type alias.
using size_type = std::uint64_t
 Size type alias (64-bit).
using difference_type = std::ptrdiff_t
 Difference type alias.
using reference = value_type &
 Reference type.
using const_reference = const value_type &
 Const reference type.
using pointer = value_type *
 Pointer type.
using const_pointer = const value_type *
 Const pointer type.
using iterator = pointer
using const_iterator = const_pointer
using allocator_type = detail::rt_arr_alloc_t<T, Alloc>

Public Member Functions

 runtime_arr (const std::uint64_t size, uninitialized_t)
 Constructs an uninitialized array of POD-like elements.
 runtime_arr (std::initializer_list< T > init)
 Constructs a fixed-size runtime array from an initializer list.
 runtime_arr (std::uint64_t size)
 Constructs a zero-initialized array using the default allocation strategy.
 runtime_arr (std::initializer_list< T > init, const Alloc &alloc)
 Constructs a fixed-size runtime array from an initializer list using a custom allocator.
 runtime_arr (std::uint64_t size, const Alloc &alloc)
 Constructs a runtime array using a movable allocator instance.
 runtime_arr (std::vector< T > &&vec)
 Constructs a runtime_arr<T> by moving from a std::vector<T> (only when Alloc is typed::monostate).
template<class VecAlloc>
requires (!typed::monostate_t<Alloc>)
 runtime_arr (std::vector< T, VecAlloc > &&vec, const Alloc &alloc)
 Constructs a runtime array by moving elements from a std::vector using a custom allocator.
 runtime_arr (std::vector< T, Alloc > &&vec)
 Constructs a runtime array by moving elements from a std::vector using its own allocator.
template<typename ForwardIt>
requires (jh::concepts::forward_iterator<ForwardIt> && (typed::monostate_t<Alloc> || std::default_initializable<Alloc>) )
 runtime_arr (ForwardIt first, ForwardIt last)
 Constructs a runtime_arr<T> from any valid forward iterator range.
template<typename ForwardIt>
requires (!typed::monostate_t<Alloc> && jh::concepts::forward_iterator<ForwardIt> && requires (ForwardIt f, ForwardIt l) { std::vector<T>(f, l); })
 runtime_arr (ForwardIt first, ForwardIt last, const Alloc &alloc)
 Constructs a runtime array from a forward iterator range using a custom allocator.
iterator begin () noexcept
 Returns iterator to the beginning.
const_iterator begin () const noexcept
 Returns const iterator to the beginning.
iterator end () noexcept
 Returns iterator to the end (past-the-last element).
const_iterator end () const noexcept
 Returns const iterator to the end (past-the-last element).
const_iterator cbegin () const noexcept
 Returns const iterator to the beginning.
const_iterator cend () const noexcept
 Returns const iterator to the end (past-the-last element).
reference operator[] (std::uint64_t index) noexcept
 Unchecked element access.
const_reference operator[] (std::uint64_t index) const noexcept
 Unchecked const element access.
reference at (std::uint64_t index)
 Bounds-checked element access.
const_reference at (std::uint64_t index) const
 Const bounds-checked element access.
template<typename... Args>
void set (std::uint64_t i, Args &&... args)
 Sets the value at given index using constructor arguments.
template<typename U = T>
void reset_all () noexcept
 Resets all elements to their default-initialized state.
size_type size () const noexcept
 Returns the number of elements in the array.
bool empty () const noexcept
 Checks whether the array is empty.
pointer data () noexcept
 Provides raw pointer access to the underlying storage.
const_pointer data () const noexcept
 Provides const raw pointer access to the underlying storage.
 runtime_arr (runtime_arr &&other) noexcept
 Constructs a new runtime_arr by taking ownership of another instance's data.
runtime_arroperator= (runtime_arr &&other) noexcept
 Replaces the contents of this runtime_arr with those of another, transferring ownership.
 operator std::vector< T > () &&
 Converts the array into a std::vector<T> by moving its contents.
 runtime_arr (const runtime_arr &)=delete
 Copy constructor is explicitly deleted.
runtime_arroperator= (const runtime_arr &)=delete
 Copy assignment operator is explicitly deleted.
std::span< value_typeas_span () noexcept
std::span< const value_typeas_span () const noexcept

Static Public Member Functions

static bool is_static_built ()

Static Public Attributes

static constexpr uninitialized_t uninitialized {}

Detailed Description

template<typename T, typename Alloc = typed::monostate>
requires detail::valid_rt_arr_allocator<T, Alloc>
class jh::runtime_arr< T, Alloc >

A move-only, fixed-capacity array with runtime-determined length and RAII-based ownership.

Template Parameters
TElement type.
AllocAllocator type — defaults to typed::monostate (uses new[] / delete[]).

Overview

Short for "runtime-sized array", this class models a heap-allocated, non-resizable container designed as a safe and expressive replacement for manual heap buffers (new T[n]).

Unlike std::vector, it forbids resizing, shrinking, or growth semantics. It focuses on semantic clarity rather than raw performance — making buffer lifetime and capacity constraints explicit.

Core Features

  • Move-only: eliminates accidental copies and aliasing.
  • RAII-managed heap buffer (via unique_ptr<T[], deleter>).
  • Optional zero-initialized or uninitialized construction.
  • STL/ranges compatible (view_interface inheritance).
  • reset_all() for fast POD reset using memset.
  • Allocator parameterization for custom memory control.
  • as_span() helper for safe interop with std::span<T>.

Default Allocation Model

  • If Alloc = typed::monostate (default):
    • Memory is allocated via new[] and released via delete[].
    • No external allocator is required.
  • If Alloc provides allocate(n) / deallocate(ptr, n):
    • Runtime allocation will use the provided allocator instance.

When to Use

  • As a fixed-capacity buffer with dynamic runtime length.
  • When std::vector's resizing semantics are undesired.
  • As a safer RAII alternative to T* arr = new T[n].

When Not to Use

  • If dynamic resizing, push/pop semantics, or polymorphic behavior is required.
  • If compile-time fixed capacity (std::array) suffices.

Interop Notes

  • Contiguous and std::span-compatible.
  • Supports range-for iteration, STL algorithms, and std::ranges::views.
  • runtime_arr<bool> provides bit-packed specialization (see below).
Note
  • Use reset_all() instead of clear().
  • Use runtime_arr<T>::uninitialized to skip default construction (POD only).
  • Copy operations are deleted; moves are noexcept.

Constructor & Destructor Documentation

◆ runtime_arr() [1/12]

template<typename T, typename Alloc = typed::monostate>
jh::runtime_arr< T, Alloc >::runtime_arr ( const std::uint64_t size,
uninitialized_t  )
inlineexplicit

Constructs an uninitialized array of POD-like elements.

Parameters
sizeThe number of elements to allocate.
  • Enabled only when jh::pod_like<T> and Alloc is typed::monostate.
  • Uses operator new[] to allocate raw storage — the memory is completely uninitialized (no zero-fill, no constructor calls).
  • For POD-like types, such uninitialized allocation is semantically safe: their lifetime is bound directly to the allocated storage, and no constructor/destructor side effects are required.
  • Intended for performance-critical contexts such as bulk I/O buffers, custom serialization, or explicit zero-fill via std::memset.
  • In practice, this behaves similarly to std::vector::reserve() — capacity is guaranteed, but elements are not value-initialized.
  • Unlike std::vector, however, runtime_arr does not incur large penalties when default-initializing POD types: its "initialized" and "uninitialized" paths compile to nearly identical code for trivial objects (difference <1%).

Performance note

For POD and trivially constructible types, both initialized and uninitialized variants of runtime_arr achieve equivalent performance. The uninitialized form primarily exists to express intent — much like calling std::vector::reserve() — signaling intent that the elements will be explicitly initialized later, and thus avoiding redundant zero-fills or value-initialization writes that compilers may otherwise emit. For POD and trivially constructible types, however, both forms typically compile to identical machine code, since their constructors are effectively no-ops.

Note: The content of the allocated memory is indeterminate until written to. Accessing any element before explicit initialization results in undefined behavior.

◆ runtime_arr() [2/12]

template<typename T, typename Alloc = typed::monostate>
jh::runtime_arr< T, Alloc >::runtime_arr ( std::initializer_list< T > init)
inline

Constructs a fixed-size runtime array from an initializer list.

Parameters
initInitializer list providing the values for each element.

Allocates a contiguous buffer of init.size() elements and performs std::uninitialized_copy to populate the storage. The array owns its memory and manages lifetime automatically.

  • Enabled only when Alloc == typed::monostate.
  • Allocates new T[init.size()] and copies or moves elements from init.
  • Ownership is managed via std::unique_ptr with default deleter.
  • Move-only type; copy operations are disabled.
Exceptions
std::bad_allocIf allocation fails.

◆ runtime_arr() [3/12]

template<typename T, typename Alloc = typed::monostate>
jh::runtime_arr< T, Alloc >::runtime_arr ( std::uint64_t size)
inlineexplicit

Constructs a zero-initialized array using the default allocation strategy.

Parameters
sizeNumber of elements to allocate and value-initialize.
  • Requires is_valid_allocator<Alloc>.
  • If Alloc is typed::monostate, storage is obtained via new T[size] and automatically released by the default deleter.
  • Otherwise, a user-provided allocator type is instantiated and used to allocate exactly size elements, with lifetime managed through a bound deleter lambda that captures both the allocator and allocation size.
  • All elements are zero-initialized (for PODs) or default-constructed (for non-PODs) immediately after allocation.
  • Semantically, this behaves like std::vector<T>(size) but without growth capacity or allocator_traits overhead.

Performance characteristics

  • For POD-like types, this path compiles down to a single contiguous allocation followed by a memset or equivalent zero-fill.
  • For non-trivial types, it performs element-wise default construction with strong exception safety guarantees.
  • No dynamic resizing or capacity growth is performed — the array size is fixed for the lifetime of the object.
  • In microbenchmarks, this constructor matches or slightly outperforms std::vector<T>(size) due to the absence of allocator-layer indirection.

Allocator semantics

  • When using a custom allocator, a lambda deleter is bound that correctly invokes alloc.deallocate(ptr, size) upon destruction.
  • This preserves RAII semantics and guarantees proper cleanup even in the presence of exceptions.
  • The allocator is captured by value, ensuring deterministic deallocation.
Note
This constructor is the canonical entry point for creating safe, fixed-size runtime arrays. It offers predictable initialization and deallocation behavior, suitable for both POD and non-POD types.

◆ runtime_arr() [4/12]

template<typename T, typename Alloc = typed::monostate>
jh::runtime_arr< T, Alloc >::runtime_arr ( std::initializer_list< T > init,
const Alloc & alloc )
inline

Constructs a fixed-size runtime array from an initializer list using a custom allocator.

Parameters
initInitializer list providing the values for each element.
allocAllocator instance used for allocation and deallocation.

Allocates init.size() elements via the provided allocator and performs std::uninitialized_copy to populate the buffer. The allocator is stored within a bound deleter lambda for correct deallocation.

  • Enabled only when Alloc != typed::monostate.
  • Performs alloc.allocate(size) and binds alloc.deallocate(ptr, size) as deleter.
  • Ensures allocator-aware destruction and exception safety.
  • Move-only type; copy operations are deleted.
Exceptions
std::bad_allocIf allocator fails to provide storage.

◆ runtime_arr() [5/12]

template<typename T, typename Alloc = typed::monostate>
jh::runtime_arr< T, Alloc >::runtime_arr ( std::uint64_t size,
const Alloc & alloc )
inlineexplicit

Constructs a runtime array using a movable allocator instance.

Parameters
sizeNumber of elements to allocate.
allocAllocator instance (may be lvalue or rvalue).
  • Enabled only when Alloc is not typed::monostate.
  • Accepts both lvalue and rvalue allocators; the allocator instance is captured by value (moved if possible) inside the deleter closure.
  • Provides full support for std::pmr::polymorphic_allocator<T> and other stateful allocators.

Design notes

  • This overload avoids unnecessary allocator copies and preserves resource binding.
  • Equivalent to the by-value form for trivially copyable allocators.
  • Ensures allocator lifetime and destruction safety via lambda capture semantics.

◆ runtime_arr() [6/12]

template<typename T, typename Alloc = typed::monostate>
jh::runtime_arr< T, Alloc >::runtime_arr ( std::vector< T > && vec)
inlineexplicit

Constructs a runtime_arr<T> by moving from a std::vector<T> (only when Alloc is typed::monostate).

Parameters
vecRvalue reference to a std::vector<T> whose contents will be moved.
  • Enabled only when Alloc == typed::monostate, ensuring consistent new[]/delete[] semantics.
  • Allocates a new contiguous buffer of vec.size() elements via operator new[].
  • Performs an element-wise move from vec into the internal storage.
  • The source vector remains in a valid but unspecified state after construction (per standard move semantics).
  • The resulting runtime_arr owns its own independent storage and does not alias vec's memory.

Rationale

  • This constructor provides a convenient transition path from STL containers to fixed-size runtime_arr semantics.
  • Unlike std::vector::reserve() or shrink_to_fit(), this operation guarantees immutability of capacity and clear ownership transfer.
  • It is intentionally limited to typed::monostate allocators to ensure predictable operator new[] / operator delete[] lifetime management without allocator-specific behavior.

Performance Notes

  • For trivially movable POD types, the move loop is typically optimized to a single memcpy by the compiler.
  • For non-trivial types, each element's move constructor is invoked individually.
  • Construction cost is proportional to O(n) moves, matching std::vector::move() semantics but with fixed-size final storage.

Example:

std::vector<MyPod> data(1024);
// Fill data...
jh::runtime_arr<MyPod> arr(std::move(data));
// arr now owns a separate buffer containing the moved elements.
A move-only, fixed-capacity array with runtime-determined length and RAII-based ownership.
Definition runtime_arr.h:367
pointer data() noexcept
Provides raw pointer access to the underlying storage.
Definition runtime_arr.h:1065

◆ runtime_arr() [7/12]

template<typename T, typename Alloc = typed::monostate>
template<class VecAlloc>
requires (!typed::monostate_t<Alloc>)
jh::runtime_arr< T, Alloc >::runtime_arr ( std::vector< T, VecAlloc > && vec,
const Alloc & alloc )
inline

Constructs a runtime array by moving elements from a std::vector using a custom allocator.

Parameters
vecSource vector whose elements will be moved.
allocAllocator instance used for allocation and deallocation.
  • Enabled only when Alloc != typed::monostate.
  • Allocates storage using the provided allocator.
  • Elements are move-constructed from vec.
  • The allocator is captured by value in the deleter.

◆ runtime_arr() [8/12]

template<typename T, typename Alloc = typed::monostate>
jh::runtime_arr< T, Alloc >::runtime_arr ( std::vector< T, Alloc > && vec)
inline

Constructs a runtime array by moving elements from a std::vector using its own allocator.

Parameters
vecSource vector whose elements will be moved.
  • Enabled only when Alloc != typed::monostate.
  • The allocator is obtained from vec.get_allocator().
  • Delegates to the constructor taking (std::vector<T, Alloc>&&, const Alloc&).
  • Elements are move-constructed from vec.
  • The allocator is captured by value in the deleter.
Note
This overload forwards the allocator obtained from vec.get_allocator() to the constructor runtime_arr(std::vector<T, VecAlloc>&&, const Alloc&).
The overload is intentionally constrained with std::same_as<typename Alloc::value_type, T>.
Unlike std::vector, jh::runtime_arr accepts any allocator that can be rebound to T (via std::allocator_traits::rebind_alloc).
In contrast, most standard containers require the allocator's value_type to exactly match the stored element type.
Without this restriction the compiler could attempt to instantiate an invalid standard container such as:
jh::runtime_arr<int, std::allocator<double>> (valid)
std::vector<int, std::allocator<double>> (ill-formed).
The constraint therefore ensures that this convenience overload is only enabled when the allocator used by the source vector is itself valid for std::vector<T>.

◆ runtime_arr() [9/12]

template<typename T, typename Alloc = typed::monostate>
template<typename ForwardIt>
requires (jh::concepts::forward_iterator<ForwardIt> && (typed::monostate_t<Alloc> || std::default_initializable<Alloc>) )
jh::runtime_arr< T, Alloc >::runtime_arr ( ForwardIt first,
ForwardIt last )
inline

Constructs a runtime_arr<T> from any valid forward iterator range.

Template Parameters
ForwardItIterator type satisfying jh::concepts::forward_iterator.
Parameters
firstBeginning of the input range.
lastEnd of the input range.
  • Enabled only when Alloc == typed::monostate and T is copy-constructible.
  • Elements in the range [first, last) are first materialized into a temporary std::vector<T>.
  • The resulting vector is then moved into the resulting runtime_arr.
  • Ownership of the final storage is managed via RAII (std::unique_ptr with custom deleter).

Behavior

  • If the range is empty, the resulting array is empty (size() == 0).
  • Element transfer follows the semantics of std::vector(first, last).
  • If iterators are wrapped with std::make_move_iterator, elements are moved rather than copied.
Note
This constructor requires jh::concepts::forward_iterator, which is intentionally slightly more permissive than std::forward_iterator. The requirement guarantees that the iterator range can be traversed multiple times without consuming the sequence.
Internally, a temporary std::vector<T> is used as a semantic container to delegate iterator handling, allocation, and exception safety to the standard library implementation.
In practice this temporary object is typically constructed directly in the caller's stack frame due to copy elision / NRVO, so no additional materialization step is introduced beyond what the vector constructor already performs.
Warning
The validity rules for the iterator range are identical to those of std::vector(ForwardIt, ForwardIt).
If the range [first, last) is invalid (for example, first logically appears after last), the behavior is undefined.
No explicit std::distance() check is performed in order to avoid introducing an additional traversal of the range. Whether the distance is evaluated, validated, or inferred depends entirely on the internal strategy chosen by the standard library implementation for the detected iterator category.
This mirrors the behavior of std::vector, where some iterator categories may trigger a distance computation while others are processed in a single-pass insertion loop.

Examples

From STL containers:

std::vector<int> v = {1, 2, 3};
jh::runtime_arr<int> a(v.begin(), v.end()); // copy
std::deque<int> d = {4, 5, 6};
jh::runtime_arr<int> b(d.begin(), d.end()); // copy
std::string s = "Hello";
std::make_move_iterator(s.begin()),
std::make_move_iterator(s.end())); // moves characters

From other iterator sources:

int raw[] = {10, 20, 30, 40};
jh::runtime_arr<int> arr(std::begin(raw), std::end(raw));
std::span<int> sp(raw);
jh::runtime_arr<int> arr2(sp.begin(), sp.end());

Applicable to any iterator pair that defines a finite range, including pointers, container iterators, and spans. Single-pass input iterators (such as std::istream_iterator) are not supported, since this constructor requires forward-iterable ranges.

Design rationale

  • This constructor acts as a universal range importer for forward-iterable sources.
  • Using std::vector as an intermediate layer delegates iterator handling, move semantics, and exception safety to the standard library.
  • The final runtime_arr is constructed by moving the temporary vector, avoiding manual range-copy logic.

◆ runtime_arr() [10/12]

template<typename T, typename Alloc = typed::monostate>
template<typename ForwardIt>
requires (!typed::monostate_t<Alloc> && jh::concepts::forward_iterator<ForwardIt> && requires (ForwardIt f, ForwardIt l) { std::vector<T>(f, l); })
jh::runtime_arr< T, Alloc >::runtime_arr ( ForwardIt first,
ForwardIt last,
const Alloc & alloc )
inline

Constructs a runtime array from a forward iterator range using a custom allocator.

Template Parameters
ForwardItForward iterator type.
Parameters
firstBeginning of range.
lastEnd of range.
allocAllocator instance used for allocation.
  • Enabled only when Alloc != typed::monostate.
  • Allocates using the provided allocator.
  • Copies elements from the iterator range.

◆ runtime_arr() [11/12]

template<typename T, typename Alloc = typed::monostate>
jh::runtime_arr< T, Alloc >::runtime_arr ( runtime_arr< T, Alloc > && other)
inlinenoexcept

Constructs a new runtime_arr by taking ownership of another instance's data.

Transfers ownership of the underlying buffer from other to this instance. After the move, other is left in a valid but empty state (size() == 0, data() == nullptr).

◆ runtime_arr() [12/12]

template<typename T, typename Alloc = typed::monostate>
jh::runtime_arr< T, Alloc >::runtime_arr ( const runtime_arr< T, Alloc > & )
delete

Copy constructor is explicitly deleted.

Copying a runtime_arr is intentionally disallowed, as the class models a fixed-size, region-bound buffer — conceptually similar to a safe version of a VLA (Variable Length Array).

Each runtime_arr instance owns a unique contiguous memory block via std::unique_ptr. Allowing copy semantics would imply duplicating or aliasing this region, violating its design goal of unique, region-local ownership.

To share or pass an existing array, use references: runtime_arr& or std::reference_wrapper<runtime_arr>. This preserves ownership while allowing safe, non-copy access across function boundaries.

Member Function Documentation

◆ at() [1/2]

template<typename T, typename Alloc = typed::monostate>
reference jh::runtime_arr< T, Alloc >::at ( std::uint64_t index)
inline

Bounds-checked element access.

Returns a reference to the element at the given index, performing explicit range checking. If index >= size(), an std::out_of_range exception is thrown.

Parameters
indexElement index within [0, size()).
Returns
Reference to the element at the specified index.
Exceptions
std::out_of_rangeIf index >= size().
See also
operator[]()

◆ at() [2/2]

template<typename T, typename Alloc = typed::monostate>
const_reference jh::runtime_arr< T, Alloc >::at ( std::uint64_t index) const
inlinenodiscard

Const bounds-checked element access.

Returns a const reference to the element at the given index, performing explicit range checking. If index >= size(), an std::out_of_range exception is thrown.

Parameters
indexElement index within [0, size()).
Returns
Const reference to the element at the specified index.
Exceptions
std::out_of_rangeIf index >= size().
See also
operator[]()

◆ data() [1/2]

template<typename T, typename Alloc = typed::monostate>
const_pointer jh::runtime_arr< T, Alloc >::data ( ) const
inlinenodiscardnoexcept

Provides const raw pointer access to the underlying storage.

Returns
Const pointer to the first element, or nullptr if empty.

◆ data() [2/2]

template<typename T, typename Alloc = typed::monostate>
pointer jh::runtime_arr< T, Alloc >::data ( )
inlinenoexcept

Provides raw pointer access to the underlying storage.

Returns
Pointer to the first element, or nullptr if empty.

◆ empty()

template<typename T, typename Alloc = typed::monostate>
bool jh::runtime_arr< T, Alloc >::empty ( ) const
inlinenodiscardnoexcept

Checks whether the array is empty.

Returns
true if size() == 0, otherwise false.

◆ operator std::vector< T >()

template<typename T, typename Alloc = typed::monostate>
jh::runtime_arr< T, Alloc >::operator std::vector< T > ( ) &&
inlineexplicit

Converts the array into a std::vector<T> by moving its contents.

This conversion performs a one-way ownership transfer from runtime_arr<T> to std::vector<T>, consuming the source in the process. After the conversion, the original runtime_arr becomes an empty, valid but unspecified object (size() == 0, data() == nullptr).

Behavior

  • POD-like types (jh::pod_like<T>): Performs a raw std::memcpy for maximal performance. The operation is equivalent to copying a contiguous byte buffer.
  • Non-POD types: Uses std::make_move_iterator to move-construct each element into the target vector, ensuring proper object semantics.

Symmetry

This operator complements the constructor runtime_arr(std::vector<T>&&), enabling seamless two-way transfer between std::vector<T> and runtime_arr<T> with full move semantics. Both conversions leave the source container in a valid but empty state, ensuring safe RAII destruction.

Note
This operator is only available on rvalues (runtime_arr<T>&&), preventing accidental copies.
See also
runtime_arr(std::vector<T>&&)

◆ operator=() [1/2]

template<typename T, typename Alloc = typed::monostate>
runtime_arr & jh::runtime_arr< T, Alloc >::operator= ( const runtime_arr< T, Alloc > & )
delete

Copy assignment operator is explicitly deleted.

Like the copy constructor, copy assignment is disabled to prevent unintended duplication of the underlying buffer. This enforces strict RAII-style ownership and guarantees deterministic lifetime management.

When sharing a buffer between scopes or functions, pass by reference (runtime_arr&) or wrap in std::reference_wrapper<runtime_arr> instead of copying.

◆ operator=() [2/2]

template<typename T, typename Alloc = typed::monostate>
runtime_arr & jh::runtime_arr< T, Alloc >::operator= ( runtime_arr< T, Alloc > && other)
inlinenoexcept

Replaces the contents of this runtime_arr with those of another, transferring ownership.

Releases any existing data owned by this instance and takes ownership of other's buffer. The source other becomes empty and remains safely destructible.

Returns
Reference to the updated *this.

◆ operator[]() [1/2]

template<typename T, typename Alloc = typed::monostate>
const_reference jh::runtime_arr< T, Alloc >::operator[] ( std::uint64_t index) const
inlinenoexcept

Unchecked const element access.

Const overload providing read-only access to the element at the given index (undefined behavior if out of range).

Parameters
indexElement index within [0, size()).
Returns
Const reference to the element.

◆ operator[]() [2/2]

template<typename T, typename Alloc = typed::monostate>
reference jh::runtime_arr< T, Alloc >::operator[] ( std::uint64_t index)
inlinenoexcept

Unchecked element access.

Returns a reference to the element at the given index without performing bounds checking (undefined behavior if out of range). Equivalent to *(data() + index).

Parameters
indexElement index within [0, size()).
Returns
Reference to the element.

◆ reset_all()

template<typename T, typename Alloc = typed::monostate>
template<typename U = T>
void jh::runtime_arr< T, Alloc >::reset_all ( )
inlinenoexcept

Resets all elements to their default-initialized state.

Reinitializes every element in the array as if assigned with T{}. The actual strategy depends on the structural properties of T:

  • POD-like types — memory is cleared with std::memset() for maximal performance and determinism.
  • Trivially destructible types — reinitialized in-place using placement-new (new(p) T{}), without invoking destructors.
  • Non-trivial types — each element is explicitly assigned T{}, invoking both destructor and constructor logic.

Implementation Notes

  • Flatten attribute: Explicit compiler flattening (e.g. [[gnu::flatten]]) was experimentally tested and removed. On LLVM Clang 20 with -O3 or higher, flatten introduced micro-jitter and inhibited certain inliner heuristics. Modern LLVM optimizers already perform ideal unrolling and hoisting automatically.
  • Template parameter U: This indirection allows SFINAE-based disabling via requires(std::is_default_constructible_v<U>) without interfering with specialized overloads — such as the runtime_arr<bool> specialization, which defines its own reset_all().
Note
This function is noexcept for all valid T.
Warning
Accessing elements before reset on uninitialized memory results in undefined behavior.

◆ set()

template<typename T, typename Alloc = typed::monostate>
template<typename... Args>
void jh::runtime_arr< T, Alloc >::set ( std::uint64_t i,
Args &&... args )
inline

Sets the value at given index using constructor arguments.

Parameters
iIndex to write to
argsArguments to construct T

◆ size()

template<typename T, typename Alloc = typed::monostate>
size_type jh::runtime_arr< T, Alloc >::size ( ) const
inlinenodiscardnoexcept

Returns the number of elements in the array.

Returns
Number of elements currently stored.

The documentation for this class was generated from the following file: