-
Notifications
You must be signed in to change notification settings - Fork 0
API muesli nullable_codec
Felix Jones edited this page Jan 15, 2026
·
1 revision
Defined in header <muesli/nullable_codec>
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
| Parameter | Description |
|---|---|
Storage |
The storage type (std::shared_ptr, std::unique_ptr, std::optional, etc. |
InnerCodec |
The codec for the contained value |
-
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.
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
| Parameter | Description |
|---|---|
Storage |
The storage type (must contain a range) |
InnerCodec |
The codec for the range |
-
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.