tagval 0.2.0
Modern C++23 header-only library of tagged values (open/closed enumerations with metadata)
Loading...
Searching...
No Matches
tagval::KindView Class Reference

Type-erased handle to one registered kind. More...

#include <kind_registry.hpp>

Public Types

using EmitFn = void(*)(void *user, const KindEntryView &)
 
using WalkFn = void(*)(void *user, EmitFn emit)
 
using FindFn = std::optional< KindEntryView >(*)(std::string_view code)
 

Public Member Functions

constexpr KindView () noexcept=default
 
constexpr TagValDescriptor descriptor () const noexcept
 
constexpr std::string_view kind_id () const noexcept
 
constexpr KindCategory category () const noexcept
 
constexpr bool is_closed_ended () const noexcept
 
constexpr bool is_open_ended () const noexcept
 
std::vector< KindEntryViewvalues () const
 Allocating snapshot of the kind's current values, in declaration order (open-ended: predefined entries followed by extern entries in registration order).
 
template<std::invocable< const KindEntryView & > F>
void for_each (F &&f) const
 Zero-allocation walk over the kind's current values.
 
std::optional< KindEntryViewfind (const std::string_view code) const
 Look up a value by code.
 

Friends

template<typename T >
class detail::KindViewFactory
 
constexpr bool operator== (const KindView &a, const KindView &b) noexcept
 

Detailed Description

Type-erased handle to one registered kind.

Stores TagValDescriptor, KindCategory, and three function pointers captured at registration time. No virtual dispatch, no allocation outside the explicit values() snapshot.

Member Typedef Documentation

◆ EmitFn

using tagval::KindView::EmitFn = void (*)(void* user, const KindEntryView&)

◆ WalkFn

using tagval::KindView::WalkFn = void (*)(void* user, EmitFn emit)

◆ FindFn

using tagval::KindView::FindFn = std::optional<KindEntryView> (*)(std::string_view code)

Constructor & Destructor Documentation

◆ KindView()

constexpr tagval::KindView::KindView ( )
constexprdefaultnoexcept

Member Function Documentation

◆ descriptor()

constexpr TagValDescriptor tagval::KindView::descriptor ( ) const
inlineconstexprnoexcept

◆ kind_id()

constexpr std::string_view tagval::KindView::kind_id ( ) const
inlineconstexprnoexcept

◆ category()

constexpr KindCategory tagval::KindView::category ( ) const
inlineconstexprnoexcept

◆ is_closed_ended()

constexpr bool tagval::KindView::is_closed_ended ( ) const
inlineconstexprnoexcept

◆ is_open_ended()

constexpr bool tagval::KindView::is_open_ended ( ) const
inlineconstexprnoexcept

◆ values()

std::vector< KindEntryView > tagval::KindView::values ( ) const
inline

Allocating snapshot of the kind's current values, in declaration order (open-ended: predefined entries followed by extern entries in registration order).

◆ for_each()

template<std::invocable< const KindEntryView & > F>
void tagval::KindView::for_each ( F &&  f) const
inline

Zero-allocation walk over the kind's current values.

f is invoked per entry. Does not own f; reference / move-capture as appropriate.

◆ find()

std::optional< KindEntryView > tagval::KindView::find ( const std::string_view  code) const
inline

Look up a value by code.

Cheaper than calling values(): goes through the kind's own try_of() path.

Friends And Related Symbol Documentation

◆ detail::KindViewFactory

template<typename T >
friend class detail::KindViewFactory
friend

◆ operator==

constexpr bool operator== ( const KindView a,
const KindView b 
)
friend

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