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, []() { ... });
A typed event that pairs an event ID with its data type.
Definition event.hpp:195

Definition at line 195 of file event.hpp.

Member Data Documentation

◆ id

template<typename IdEnum , typename DataType = void>
IdEnum idfxx::event< IdEnum, DataType >::id

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