Skip to content

API muesli nullable_codec

Felix Jones edited this page Jan 15, 2026 · 1 revision

muesli/nullable_codec

Defined in header <muesli/nullable_codec>

make_nullable

template<typename Storage, Codec InnerCodec> requires(!std::is_pointer_v<Storage>) constexpr auto make_nullable(const InnerCodec& inner)

Creates a nullable codec for smart pointers and optional-like types

Template Parameters

Parameter Description
Storage The storage type (std::shared_ptr, std::unique_ptr, std::optional, etc.
InnerCodec The codec for the contained value

Parameters

  • inner — The codec to use for the contained value

Returns: A codec that encodes/decodes nullable storage types Encodes nullptr/nullopt as absent optional values. Non-null values are encoded using the inner codec and reconstructed on decode.


make_nullable_range

template<typename Storage, Codec InnerCodec> requires(!std::is_pointer_v<Storage>) constexpr auto make_nullable_range(const InnerCodec& inner)

Creates a nullable codec that treats empty ranges as null

Template Parameters

Parameter Description
Storage The storage type (must contain a range)
InnerCodec The codec for the range

Parameters

  • inner — The codec to use for the range

Returns: A codec that treats empty ranges as null Unlike regular make_nullable, this encodes empty ranges as empty (not as optional absent). This saves bytes when encoding empty containers as they're encoded the same as nullptr.


Clone this wiki locally