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

POD-safe optional<T> with raw storage. More...

#include "jh/pods/pod_like.h"
#include <new>
#include <cstddef>
#include <cstring>
#include <memory>

Go to the source code of this file.

Classes

struct  jh::pod::optional< T >
 POD-compatible optional wrapper. More...

Namespaces

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

Functions

template<pod_like T>
constexpr optional< T > jh::pod::make_optional (const T &value) noexcept
 Construct an optional<T> with a value.

Detailed Description

POD-safe optional<T> with raw storage.

Design Goals:

  • Strict POD semantics (pod_like required)
  • Raw byte buffer + 1 flag, no constructors or destructors
  • Safe in pod::array, serialization, and mmap'd memory
  • ABI predictable (sizeof(optional<T>) == sizeof(T) + 1)
Note
Unlike std::optional, this type never runs constructors or destructors.
Functions rely on reinterpret_cast/std::launder and therefore cannot be used in consteval contexts.