parcel 0.2.2
Wrappable, wire-transferable C++23 value system with JSON serialization
Loading...
Searching...
No Matches
union.h File Reference

UnionCell<Ts...> closed-set polymorphic cell and its descriptor. More...

#include <parcel/cell.h>
#include <parcel/descriptor.h>
#include <array>
#include <cstddef>
#include <memory>
#include <stdexcept>
#include <string>
#include <string_view>
#include <tuple>
#include <type_traits>
#include <utility>
#include <variant>
Include dependency graph for union.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  parcel::UnionCellTypeDescriptor< Ts >
 Descriptor for UnionCell<Ts...>. More...
 
class  parcel::UnionCell< Ts >
 Closed-set polymorphic cell — exactly one of Ts at runtime. More...
 
struct  parcel::Overload< Fs >
 Lambda-overload set helper for parcel::visit. More...
 

Functions

template<typename F , CellLike... Ts>
decltype(auto) parcel::visit (F &&f, UnionCell< Ts... > &u)
 std::visit-style free function over UnionCell<Ts...>.
 
template<typename F , CellLike... Ts>
decltype(auto) parcel::visit (F &&f, UnionCell< Ts... > const &u)
 Const overload of visit.
 
template<std::size_t I, CellLike... Ts>
auto & parcel::get (UnionCell< Ts... > &u)
 Free get<I> over UnionCell<Ts...> mirroring std::get<I>(variant).
 
template<typename S , CellLike... Ts>
S & parcel::get (UnionCell< Ts... > &u)
 Free get<S> selecting by storage type.
 
template<std::size_t I, CellLike... Ts>
auto * parcel::get_if (UnionCell< Ts... > *u) noexcept
 Free get_if<I> over UnionCell<Ts...>; returns nullptr on miss.
 

Detailed Description

UnionCell<Ts...> closed-set polymorphic cell and its descriptor.

A UnionCell<Ts...> holds exactly one value drawn from a fixed set of cell alternatives. Storage is std::variant<typename Ts::storage_t...>. The wire kind id encodes every alternative kind in template order so each instantiation registers under its own kind. See the README "Unions" section.

Function Documentation

◆ visit()

template<typename F , CellLike... Ts>
decltype(auto) parcel::visit ( F &&  f,
UnionCell< Ts... > &  u 
)

std::visit-style free function over UnionCell<Ts...>.

Calls f on the active alternative's storage. Mirrors std::visit(visitor, variant).