idfxx 1.0.0
Modern C++23 components for ESP-IDF
Loading...
Searching...
No Matches
idfxx::event< IdEnum, DataType > Struct Template Reference

A typed event that pairs an event ID with its data type. More...

Public Attributes

IdEnum id
 The event ID.
 

Detailed Description

template<typename IdEnum, typename DataType = void>
requires (std::is_void_v<DataType> || receivable_event_data<DataType>)
struct idfxx::event< IdEnum, DataType >

A typed event that pairs an event ID with its data type.

Used to register type-safe event listeners where the callback receives the correct data type directly, rather than a raw void pointer. The event base is looked up automatically from the enum type via ADL (see IDFXX_EVENT_DEFINE_BASE).

Warning
Only one event should be defined per enum value. Defining multiple events with the same ID but different data types is not detected at compile time and will result in undefined behavior (the listener will attempt to reconstruct the wrong type from the event data).
Template Parameters
IdEnumThe event ID enum type.
DataTypeThe event data type (must satisfy receivable_event_data), or void for events without data.
// Define typed events
inline constexpr event<my_event, my_data> data_event{my_event::with_data};
inline constexpr event<my_event> simple_event{my_event::no_data};
// Register type-safe listeners
loop.listener_add(data_event, [](const my_data& d) { ... });
loop.listener_add(simple_event, []() { ... });
std::expected< T, std::error_code > result
result type wrapping a value or error code.
Definition error.hpp:120

Definition at line 195 of file event.hpp.

Member Data Documentation

◆ id

The event ID.

Definition at line 199 of file event.hpp.

Referenced by idfxx::event_loop::try_listener_add().


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