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::pod::array< T, N > Struct Template Referencefinal

POD-compatible fixed-size array, similar in shape to std::array, but simpler and fully POD. More...

#include <jh/pods/array.h>

Public Types

using value_type = T
 Value type alias.
using size_type = std::uint16_t
 Size type alias (16-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.

Public Member Functions

constexpr reference operator[] (std::size_t i) noexcept
 Access element by index (no bounds checking).
constexpr const_reference operator[] (std::size_t i) const noexcept
 Access element by index (const, no bounds checking).
constexpr pointer begin () noexcept
 Get pointer to beginning of array.
constexpr const_pointer begin () const noexcept
 Get const pointer to beginning of array.
constexpr pointer end () noexcept
 Get pointer to end of array (one past last element).
constexpr const_pointer end () const noexcept
 Get const pointer to end of array (one past last element).
constexpr bool operator== (const array &) const =default
 Compare two arrays for equality (element-wise).

Static Public Member Functions

static constexpr size_type size () noexcept
 Return the number of elements in the array.

Public Attributes

data [N]
 Inline contiguous storage for N elements of type T.

Detailed Description

template<cv_free_pod_like T, std::uint16_t N>
requires (sizeof(T) * N <= max_pod_array_bytes)
struct jh::pod::array< T, N >

POD-compatible fixed-size array, similar in shape to std::array, but simpler and fully POD.

Template Parameters
TElement type. Must satisfy pod_like<T> and must be free of const/volatile qualifiers (i.e. satisfy cv_free_pod_like<T>). Using const T or volatile T would make the array itself non-POD due to loss of trivial assignment and copy semantics.
NNumber of elements. Total memory (sizeof(T) * N) must not exceed 16KB.

This structure is designed for:

  • Raw memory containers (jh::runtime_arr, arena)
  • In-place value blocks (placement-new, mmap, .data segments)
  • Zero-allocation, constexpr-safe stack usage

Design Constraints:

  • Memory is fully inline and contiguous (T data[N])
  • Compile-time limited to 16KB for safety and portability
  • Supports operator[], range-based for-loops, == comparison
  • No bounds checking — required to preserve POD/constexpr/noexcept semantics. Since the layout is trivial, most out-of-bounds cases can be caught at compile-time.
Note
This is not a drop-in replacement for std::array. It has:
  • No .at(), .fill(), .swap() helpers
  • No allocator, and bounds safety deliberately omitted to retain POD/constexpr semantics
Warning
Do not use this for large arrays or heap-like buffers.

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