-
Notifications
You must be signed in to change notification settings - Fork 0
API muesli util concepts
Defined in header <muesli/util/concepts>
struct is_variant : std::false_typeTrait to detect std::variant types
Provides a type trait to check if a type is a std::variant. Useful for compile-time type checking and specialisation.
- is_variant_v for the value form
- Inherits from:
std::false_type
template<typename T> inline constexpr bool is_variant_v = is_variant<T>::value; /** * @brief Concept for types that can be converted to bool * * Requires types to support explicit conversion to bool, such as: * - std::optional * - std::unique_ptr / std::shared_ptr * - Custom types with operator bool() * * @code * struct OptionalValue template for detecting std::variant types
Convenient boolean constant to check if a type is a std::variant.
concept HasBoolConversionConcept for types that can be converted to bool
Requires types to support explicit conversion to bool, such as:
- std::optional
- std::unique_ptr / std::shared_ptr
- Custom types with operator bool()
struct Optional {
operator bool() const { return has_value; }
bool has_value = false;
};
static_assert(HasBoolConversion<Optional>);concept HasHasValueConcept for types with a has_value() method
Requires types to provide a has_value() method that returns a boolean. Used for std::optional-like types.
std::optional<int> opt = 42;
static_assert(HasHasValue<decltype(opt)>);concept HasOptionalValueCheckConcept for optional-like types with value checking
Composite concept that checks for either bool conversion OR has_value() method. Covers all common optional/nullable types:
- std::optional
- std::shared_ptr
- std::unique_ptr
- Raw pointers
concept HasValueTypeConcept for types with a value_type member
Requires types to define a value_type member type. Typically used for container and codec types.
concept HasNextCodecConcept for codecs with a next_codec() method
Core requirement for codec types - they must provide a next_codec() method that returns the next codec in the encoding chain.
concept CanEncodeRvalueConcept for codecs that can encode rvalue references
Requires codecs to accept an rvalue reference to their value_type and return the encoded type as an rvalue reference.
template<typename C>
requires CanEncodeRvalue<C>
void encode_temp(const C& codec) {
typename C::value_type temp = ...;
auto encoded = codec.encode(std::move(temp));
}concept CanEncodeConstRefConcept for codecs that can encode const references
Requires codecs to accept a const reference to their value_type and return the encoded type.
concept CanDecodeRvalueConcept for codecs that can decode rvalue references
Requires codecs to accept an rvalue reference to their encoded_type and return the decoded value_type as an rvalue reference.
concept CanDecodeConstRefConcept for codecs that can decode const references
Requires codecs to accept a const reference to their encoded_type and return the decoded value_type.
concept CodecMain Codec concept - defines the encoding/decoding interface
The core concept that all codecs must match. Requires:
- A value_type member for the type being encoded/decoded
- A next_codec() method that returns the next codec in the chain
- Ability to encode and decode values (either as rvalues or const references)
This is the foundation for the entire muesli codec framework. Any type satisfying this concept can be used with all codec composition operations.
// All of these satisfy the Codec concept:
identity_codec<int>
array_codec<identity_codec<int>, 3>
optional_codec<identity_codec<int>>
tuple_codec<identity_codec<int>, identity_codec<float>>
static_assert(Codec<identity_codec<int>>);concept HasProjectToEncodedConcept for types with a project() method that returns an encoded type
Used by projector_codec to check if a type can project a value to the encoded representation.
concept HasProjectFromOwnerConcept for types with a project() method given an owner type
Checks if a codec can project from an owner type. Used by tuple_codec to verify all elements support projection.
template<T>
struct has_tuple_get_rangeHelper trait for checking tuple element access
Recursively checks if all elements of a tuple can be accessed via std::get. Used to verify tuple types are valid for tuple_codec.
- Related codecs:
tuple_codec
concept HasTupleGetUpToConcept for tuples that support get<0> through get
concept HasNulloptConstructibleConcept for types constructible from std::nullopt
template<T, Variant>
struct is_constructible_from_all_variant_alternativesTrait to check if type is constructible from all variant alternatives
concept ConstructibleFromAllVariantAlternativesConcept for types constructible from all alternatives in a variant
concept HasTupleSizeConcept that detects presence of std::tuple_size specialisation
Satisfied for tuple-like types (std::tuple, std::pair, etc.). Avoids instantiating tuple_size_v on non-tuples.