Skip to content

API muesli identity_codec

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

muesli/identity_codec

Defined in header <muesli/identity_codec>

identity_codec

template<T>
struct identity_codec : fluent::optionable<identity_codec<T>>,
                        fluent::constrainable<identity_codec<T>>,
                        fluent::projectable<identity_codec<T>>,
                        fluent::transformable<identity_codec<T>>,
                        fluent::nullableable<identity_codec<T>>,
                        fluent::constructable<identity_codec<T>>

The simplest codec - passes values through unchanged

The identity_codec is a no-op codec that encodes and decodes by simply returning the value as-is. This is useful as a building block for more complex codecs and as a codec for primitive types.

Template parameters:

  • T: The type to encode/decode

Example usage:

auto codec = muesli::identity_codec<int>();
int value = 54;
auto encoded = codec.encode(value);  // Returns 54
auto decoded = codec.decode(encoded); // Returns 54

Member Types

value_type

using value_type = T

The type that this codec encodes and decodes

Member Functions

decode

Returns the value unchanged (rvalue overload)

static constexpr value_type&& decode(value_type&& value) noexcept
static constexpr const value_type& decode(const value_type& value) noexcept

encode

Returns the value unchanged (rvalue overload)

static constexpr value_type&& encode(value_type&& value) noexcept
static constexpr const value_type& encode(const value_type& value) noexcept

next_codec

Returns itself as the next codec (identity operation)

constexpr const identity_codec& next_codec() const noexcept

Notes

This codec has zero overhead - encode and decode are inline no-ops.

Example

auto codec = muesli::identity_codec<int>();
int value = 54;
auto encoded = codec.encode(value);  // Returns 54
auto decoded = codec.decode(encoded); // Returns 54

next_codec

using value_type = T; /** @brief Returns itself as the next codec (identity operation) */ constexpr const identity_codec& next_codec() const noexcept

The type that this codec encodes and decodes


encode

static constexpr value_type&& encode(value_type&& value) noexcept

Returns the value unchanged (rvalue overload)


decode

static constexpr value_type&& decode(value_type&& value) noexcept

Returns the value unchanged (rvalue overload)


Clone this wiki locally