tagval 0.2.0
Modern C++23 header-only library of tagged values (open/closed enumerations with metadata)
Loading...
Searching...
No Matches
tagval::ClosedEnded< Id, Derived > Class Template Reference

CRTP base for tag-value kinds whose values are fixed at compile time. More...

#include <closed_ended.hpp>

+ Inheritance diagram for tagval::ClosedEnded< Id, Derived >:
+ Collaboration diagram for tagval::ClosedEnded< Id, Derived >:

Static Public Member Functions

template<typename E >
static const Derived & value () noexcept
 Compile-time canonical handle for an entry.
 
static std::span< const TagValMetadataall_values () noexcept
 All values for this kind, in declaration order.
 
static Derived of (std::string_view code)
 Look up a value by code. Throws UnknownCodeError on miss.
 
static std::expected< Derived, ParseErrortry_of (std::string_view code) noexcept
 Look up a value by code. Returns ParseError on miss.
 
- Static Public Member Functions inherited from tagval::detail::HandleBase< Id, Derived >
static constexpr std::string_view kind_id () noexcept
 
static constexpr TagValDescriptor descriptor () noexcept
 

Additional Inherited Members

- Public Member Functions inherited from tagval::detail::HandleBase< Id, Derived >
constexpr HandleBase () noexcept=default
 Default-constructed handle: empty(), bool() == false.
 
std::string_view code () const noexcept
 
std::string_view label () const noexcept
 
std::optional< comms::Icon > icon () const noexcept
 
std::optional< comms::Color > color () const noexcept
 
bool empty () const noexcept
 
 operator bool () const noexcept
 
- Protected Member Functions inherited from tagval::detail::HandleBase< Id, Derived >
constexpr HandleBase (const TagValMetadata *m) noexcept
 
- Static Protected Member Functions inherited from tagval::detail::HandleBase< Id, Derived >
static Derived make_handle (const TagValMetadata *m) noexcept
 Build a Derived handle from a stable metadata pointer.
 
static const TagValMetadatafind_in (const std::span< const TagValMetadata > values, const std::string_view code) noexcept
 Linear search a metadata range by code.
 
static Derived of_impl (const std::span< const TagValMetadata > values, const std::string_view code)
 
static std::expected< Derived, ParseErrortry_of_impl (const std::span< const TagValMetadata > values, const std::string_view code) noexcept
 
- Protected Attributes inherited from tagval::detail::HandleBase< Id, Derived >
const TagValMetadatameta_ = nullptr
 

Detailed Description

template<comms::FixedString Id, typename Derived>
class tagval::ClosedEnded< Id, Derived >

CRTP base for tag-value kinds whose values are fixed at compile time.

class Status : public tagval::ClosedEnded<"status", Status> {
public:
    using base_t = tagval::ClosedEnded<"status", Status>;
    using base_t::base_t;
    TAGVAL_ENTRY(Status, Active,   active);
    TAGVAL_ENTRY(Status, Inactive, inactive, "Inactive");
    using values_t = tagval::Values<Active, Inactive>;
}; 

Member Function Documentation

◆ value()

template<comms::FixedString Id, typename Derived >
template<typename E >
static const Derived & tagval::ClosedEnded< Id, Derived >::value ( )
inlinestaticnoexcept

Compile-time canonical handle for an entry.

Static-asserts the entry is listed in Derived::values_t. The handle's address is the address of the matching record inside all_values(), so it compares equal to the result of of(E::code).

◆ all_values()

template<comms::FixedString Id, typename Derived >
static std::span< const TagValMetadata > tagval::ClosedEnded< Id, Derived >::all_values ( )
inlinestaticnoexcept

All values for this kind, in declaration order.

Span points into a constexpr static array — valid for the program's lifetime.

◆ of()

template<comms::FixedString Id, typename Derived >
static Derived tagval::ClosedEnded< Id, Derived >::of ( std::string_view  code)
inlinestatic

Look up a value by code. Throws UnknownCodeError on miss.

◆ try_of()

template<comms::FixedString Id, typename Derived >
static std::expected< Derived, ParseError > tagval::ClosedEnded< Id, Derived >::try_of ( std::string_view  code)
inlinestaticnoexcept

Look up a value by code. Returns ParseError on miss.


The documentation for this class was generated from the following file: