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 Namespace Reference

Aggregated entry point for Plain-Old-Data and layout-stable value utilities. More...

Namespaces

namespace  literals
 Official literal helpers for jh::pod types.

Classes

struct  array
 POD-compatible fixed-size array, similar in shape to std::array, but simpler and fully POD. More...
struct  bitflags
 POD-compatible fixed-size bitflags structure.Generic fallback specialization for non-native sizes (e.g. 24, 120 bits, etc). More...
struct  bitflags< 8 >
 Specialization for 8-bit bitflags. More...
struct  bitflags< 16 >
 Specialization for 16-bit bitflags. More...
struct  bitflags< 32 >
 Specialization for 32-bit bitflags. More...
struct  bitflags< 64 >
 Specialization for 64-bit bitflags. More...
struct  bytes_view
 A read-only view over a block of raw bytes. More...
struct  optional
 POD-compatible optional wrapper. More...
struct  pair
 POD-compatible aggregate of two values, equivalent in layout to a plain struct. More...
struct  span
 Non-owning typed view over a contiguous memory block. More...
struct  string_view
 Read-only string view with POD layout. More...
struct  tuple
 POD-compatible tuple type supporting structured bindings and tuple-like utilities. More...

Concepts

concept  std_uint
 Internal constraint for native unsigned integer types.
concept  trivial_bytes
 Concept for trivially layout-compatible types (POD-compatible memory view).
concept  pod_like
 Concept for types that are safe to treat as plain old data (POD).
concept  cv_free_pod_like
 Concept for POD-like types that are free of const or volatile qualification.
concept  streamable
 Checks whether a type can be streamed to std::ostream.
concept  streamable_pod
 Debug-only constraint for POD-like types printable to std::ostream.

Functions

template<std_uint UInt>
constexpr auto uint_to_bytes (const UInt val)
 Convert an unsigned integer into a little-endian byte array.
template<std::uint16_t N>
constexpr auto bytes_to_uint (const array< std::uint8_t, N > &arr)
 Convert a little-endian byte array into an unsigned integer.
template<std::uint16_t N>
constexpr bitflags< N > operator| (const bitflags< N > &lhs, const bitflags< N > &rhs) noexcept
template<std::uint16_t N>
constexpr bitflags< N > operator& (const bitflags< N > &lhs, const bitflags< N > &rhs) noexcept
template<std::uint16_t N>
constexpr bitflags< N > operator^ (const bitflags< N > &lhs, const bitflags< N > &rhs) noexcept
template<std::uint16_t N>
constexpr bitflags< N > operator~ (const bitflags< N > &v) noexcept
template<std::uint16_t N>
constexpr array< std::uint8_t, N/8 > to_bytes (bitflags< N > f)
 Serialize a bitflags<N> into a little-endian byte array (snapshot).
template<std::uint16_t N>
constexpr bitflags< N > from_bytes (array< std::uint8_t, N/8 > arr)
 Deserialize a bitflags<N> from a byte array (snapshot).
template<pod_like T>
constexpr optional< T > make_optional (const T &value) noexcept
 Construct an optional<T> with a value.
template<cv_free_pod_like T1, cv_free_pod_like T2>
constexpr auto make_pair (T1 first, T2 second) noexcept
 Constructs a POD-compatible pair from two values.
template<typename T, std::uint64_t N>
constexpr span< T > to_span (T(&arr)[N]) noexcept
 Create span from a raw array (T[N]).
template<typename T, std::uint64_t N>
constexpr span< const T > to_span (const T(&arr)[N]) noexcept
 Create span from a const raw array (const T[N]).
template<detail::linear_container C>
constexpr auto to_span (C &c) noexcept
 Creates a POD-compatible span from a linear container.
template<streamable T, std::uint16_t N>
std::ostream & operator<< (std::ostream &os, const jh::pod::array< T, N > &arr)
template<std::uint16_t N>
std::ostream & operator<< (std::ostream &os, const jh::pod::array< char, N > &str)
std::ostream & operator<< (std::ostream &os, jh::typed::monostate &)
template<streamable T1, streamable T2>
std::ostream & operator<< (std::ostream &os, const jh::pod::pair< T1, T2 > &t)
template<streamable T>
std::ostream & operator<< (std::ostream &os, const jh::pod::optional< T > &opt)
template<std::uint16_t N>
std::ostream & operator<< (std::ostream &os, const jh::pod::bitflags< N > &flags)
std::ostream & operator<< (std::ostream &os, const jh::pod::bytes_view bv)
template<streamable T>
std::ostream & operator<< (std::ostream &os, const span< T > &sp)
std::ostream & operator<< (std::ostream &os, const string_view &sv)
template<streamable_pod Pod>
std::string to_string (const Pod &p)
template<streamable... Ts>
std::ostream & operator<< (std::ostream &os, const jh::pod::tuple< Ts... > &t)
template<std::size_t I, typename... Ts>
constexpr decltype(auto) get (tuple< Ts... > &t) noexcept
template<std::size_t I, typename... Ts>
constexpr auto get (const tuple< Ts... > &t) noexcept
template<std::size_t I, typename T1, typename T2>
constexpr decltype(auto) get (jh::pod::pair< T1, T2 > &p) noexcept
template<std::size_t I, typename T1, typename T2>
constexpr decltype(auto) get (const jh::pod::pair< T1, T2 > &p) noexcept
template<std::size_t I, typename T, std::uint16_t N>
constexpr decltype(auto) get (jh::pod::array< T, N > &a) noexcept
template<std::size_t I, typename T, std::uint16_t N>
constexpr decltype(auto) get (const jh::pod::array< T, N > &a) noexcept
template<typename... Ts>
constexpr auto make_tuple (Ts &&... args) noexcept
 Constructs a POD-compatible tuple from given arguments.
template<typename... Ts>
constexpr bool operator== (const tuple< Ts... > &lhs, const tuple< Ts... > &rhs) noexcept
template<typename... Ts>
constexpr bool operator!= (const tuple< Ts... > &lhs, const tuple< Ts... > &rhs) noexcept

Variables

constexpr std::uint16_t max_pod_array_bytes = 16 * 1024
 Maximum size of a POD array (16KB). This is a compile-time constant.
constexpr std::uint16_t max_pod_bitflags_bytes = 4 * 1024
 Maximum allowed size of a POD bitflags structure: 4KB (4096 bytes).
template<std::uint16_t N>
constexpr bool is_native_bitflags = N == 8 || N == 16 || N == 32 || N == 64

Detailed Description

Aggregated entry point for Plain-Old-Data and layout-stable value utilities.

The <jh/pod> forwarding header provides a unified, low-level interface over the POD-oriented components implemented under jh/pods/.
This module defines a collection of layout-deterministic, trivially copyable value types designed for binary safety, predictable memory representation, and zero-overhead abstraction.
All types and utilities exposed through jh::pod are defined in terms of the jh::pod::pod_like contract, ensuring standard layout, trivial lifetime semantics, and safe use in serialization, memory mapping, and low-level data transport.

See also
jh::pod::pod_like

Function Documentation

◆ bytes_to_uint()

template<std::uint16_t N>
auto jh::pod::bytes_to_uint ( const array< std::uint8_t, N > & arr)
nodiscardconstexpr

Convert a little-endian byte array into an unsigned integer.

Note
Only valid for native sizes: 1, 2, 4, 8 bytes.
Template Parameters
NByte count.
Parameters
arrInput array.
Returns
Corresponding unsigned integer of size N * 8.

◆ from_bytes()

template<std::uint16_t N>
bitflags< N > jh::pod::from_bytes ( array< std::uint8_t, N/8 > arr)
constexpr

Deserialize a bitflags<N> from a byte array (snapshot).

Note
Only the array's raw content is used. No semantic validation is performed.

◆ make_optional()

template<pod_like T>
optional< T > jh::pod::make_optional ( const T & value)
nodiscardconstexprnoexcept

Construct an optional<T> with a value.

Parameters
valueValue to copy into optional.
Returns
Filled optional<T> with .has() == true.

◆ make_pair()

template<cv_free_pod_like T1, cv_free_pod_like T2>
auto jh::pod::make_pair ( T1 first,
T2 second )
constexprnoexcept

Constructs a POD-compatible pair from two values.

This function aligns with std::make_pair for interface consistency. It performs no special handling beyond aggregate initialization and exists solely to provide a familiar, STL-compatible API name.

Template Parameters
T1Type of the first element.
T2Type of the second element.
Parameters
firstFirst element value.
secondSecond element value.
Returns
A jh::pod::pair<T1, T2> containing the given elements.
See also
jh::pod::pair

◆ make_tuple()

template<typename... Ts>
auto jh::pod::make_tuple ( Ts &&... args)
constexprnoexcept

Constructs a POD-compatible tuple from given arguments.

This is the general-purpose tuple construction interface aligned with std::make_tuple, but restricted to POD-compatible types. Each element is assigned by index, ensuring consistent aggregate initialization semantics across compilers.

  • Portable alternative to direct brace initialization
  • Preserves POD guarantees of jh::pod::tuple
  • Automatically decays arguments to their underlying types
Note
Arrays and string literals decay to pointers when passed by value. To preserve the complete POD content and avoid type decay, wrap them explicitly with jh::pod::array<T, N> or jh::pod::array<char, N> when constructing tuples.
Template Parameters
TsVariadic list of POD-compatible argument types.
Parameters
argsThe values to store in the tuple.
Returns
A jh::pod::tuple containing the given values.
See also
jh::pod::tuple

◆ to_bytes()

template<std::uint16_t N>
array< std::uint8_t, N/8 > jh::pod::to_bytes ( bitflags< N > f)
nodiscardconstexpr

Serialize a bitflags<N> into a little-endian byte array (snapshot).

Note
The output is always little-endian, regardless of host architecture.

◆ to_span()

template<detail::linear_container C>
auto jh::pod::to_span ( C & c)
nodiscardconstexprnoexcept

Creates a POD-compatible span from a linear container.

This function constructs a span<T> that references the contiguous data region of a container C. The access method (field, member function, or ADL helper) is determined at compile time according to the precomputed linear_status<C>.

Design Rationale

Accessor detection follows a fixed precedence:
ADL (get_data(), get_size()) → field (data, len) → member function (data(), size()).
This allows users to explicitly provide ADL overloads to override internal members when the container layout is not standard or may be misleading.

Note
  • data and data() are mutually exclusive — defining both is undefined behavior.
  • len and size() may coexist, but they are expected to report identical lengths.
  • If your container exposes inconsistent or unexpected accessors, you can define my_ns::get_size(my_ns::MyContainer) or get_data() via ADL to override detection.
  • If even ADL overrides cannot match your intended semantics, do not use this helper — manually construct span{ptr, len} instead.
  • This is a syntactic convenience, not a semantic requirement.

Return Value

Returns a non-owning span<Elem> referencing the same contiguous memory as the source container.

◆ uint_to_bytes()

template<std_uint UInt>
auto jh::pod::uint_to_bytes ( const UInt val)
nodiscardconstexpr

Convert an unsigned integer into a little-endian byte array.

Note
Always little-endian, regardless of platform endianness.
Template Parameters
UIntMust be one of: uint8_t, uint16_t, uint32_t, uint64_t.
Parameters
valThe input value to encode.
Returns
array<uint8_t, sizeof(UInt)> encoded in little-endian order.