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
bits.h File Reference

POD-compatible fixed-size bitflag storage (jh::pod::bitflags<N>). More...

#include <cstdint>
#include <type_traits>
#include "jh/pods/array.h"
#include "jh/macros/platform.h"
#include <bit>

Go to the source code of this file.

Classes

struct  jh::pod::bitflags< N >
 POD-compatible fixed-size bitflags structure.Generic fallback specialization for non-native sizes (e.g. 24, 120 bits, etc). More...
struct  jh::pod::bitflags< 8 >
 Specialization for 8-bit bitflags. More...
struct  jh::pod::bitflags< 16 >
 Specialization for 16-bit bitflags. More...
struct  jh::pod::bitflags< 32 >
 Specialization for 32-bit bitflags. More...
struct  jh::pod::bitflags< 64 >
 Specialization for 64-bit bitflags. More...

Namespaces

namespace  jh::pod
 Aggregated entry point for Plain-Old-Data and layout-stable value utilities.

Concepts

concept  jh::pod::std_uint
 Internal constraint for native unsigned integer types.

Functions

template<std_uint UInt>
constexpr auto jh::pod::uint_to_bytes (const UInt val)
 Convert an unsigned integer into a little-endian byte array.
template<std::uint16_t N>
constexpr auto jh::pod::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 > jh::pod::operator| (const bitflags< N > &lhs, const bitflags< N > &rhs) noexcept
template<std::uint16_t N>
constexpr bitflags< N > jh::pod::operator& (const bitflags< N > &lhs, const bitflags< N > &rhs) noexcept
template<std::uint16_t N>
constexpr bitflags< N > jh::pod::operator^ (const bitflags< N > &lhs, const bitflags< N > &rhs) noexcept
template<std::uint16_t N>
constexpr bitflags< N > jh::pod::operator~ (const bitflags< N > &v) noexcept
template<std::uint16_t N>
constexpr array< std::uint8_t, N/8 > jh::pod::to_bytes (bitflags< N > f)
 Serialize a bitflags<N> into a little-endian byte array (snapshot).
template<std::uint16_t N>
constexpr bitflags< N > jh::pod::from_bytes (array< std::uint8_t, N/8 > arr)
 Deserialize a bitflags<N> from a byte array (snapshot).

Variables

constexpr std::uint16_t jh::pod::max_pod_bitflags_bytes = 4 * 1024
 Maximum allowed size of a POD bitflags structure: 4KB (4096 bytes).
template<std::uint16_t N>
constexpr bool jh::pod::is_native_bitflags = N == 8 || N == 16 || N == 32 || N == 64

Detailed Description

POD-compatible fixed-size bitflag storage (jh::pod::bitflags<N>).

Design Goals

  • POD-only: trivially copyable, standard layout, no constructors or destructors
  • Compact: exactly N/8 bytes of storage (or one native integer)
  • Deterministic ABI: safe for memcpy, file mapping, and raw buffers
  • Constexpr-friendly: most operations available at compile-time
  • No runtime overhead: zero dynamic allocation, no virtual dispatch
Note
Unlike std::bitset, this type:
  • Has a fixed ABI and is always POD
  • Provides minimal, direct bitwise operations
  • Is explicitly designed for low-level containers and serialization