libdonut  2.3.2
Application framework for cross-platform game development in C++20
Functions | Variables
donut::reflection Namespace Reference

Functions

constexpr auto fields (auto &&aggregate) noexcept
 Get a tuple of references to each of the fields of an aggregate. More...
 
template<std::size_t N>
constexpr void forEachIndex (auto fn)
 Execute a function once for each index in the sequence from 0 up to, but not including, a given count N. More...
 
constexpr void forEach (auto &&tuple, auto fn)
 Execute a function once for each element in a given tuple, sequentially. More...
 
constexpr auto transform (auto &&tuple, auto fn)
 Execute a function for each element in a given tuple and return a tuple containing the results. More...
 

Variables

template<typename T >
constexpr std::size_t aggregate_size_v = aggregate_size<T>::value
 The number of fields in a given aggregate type. More...
 

Function Documentation

◆ fields()

constexpr auto donut::reflection::fields ( auto &&  aggregate)
constexprnoexcept

Get a tuple of references to each of the fields of an aggregate.

Parameters
aggregatea forwarding reference to an object of aggregate type.
Returns
a tuple where each element is an lvalue reference to the respective field of the aggregate, based on the declaration order of the fields.
Warning
Only aggregate sizes up to 26 are supported. If the function is instantiated with an aggregate type containing more than 26 fields, the program is ill-formed.

◆ forEachIndex()

template<std::size_t N>
constexpr void donut::reflection::forEachIndex ( auto  fn)
constexpr

Execute a function once for each index in the sequence from 0 up to, but not including, a given count N.

The callback function is passed an instance of std::integral_constant<std::size_t, I> where I is the corresponding index.

Template Parameters
Nthe number of indices in the sequence.
Parameters
fnthe function to execute. Must accept an object of type std::integral_constant<std::size_t, I> as a parameter, where I is any integer from 0 up to, but not including, N.
Exceptions
anyexception thrown by fn.

◆ forEach()

constexpr void donut::reflection::forEach ( auto &&  tuple,
auto  fn 
)
constexpr

Execute a function once for each element in a given tuple, sequentially.

The callback function is passed a reference to the element at each respective index of the tuple.

Parameters
tuplethe tuple to iterate.
fnthe function to execute. Must accept a reference to each of the types in the tuple as a parameter.
Exceptions
anyexception thrown by fn.

◆ transform()

constexpr auto donut::reflection::transform ( auto &&  tuple,
auto  fn 
)
constexpr

Execute a function for each element in a given tuple and return a tuple containing the results.

The callback function is passed a reference to the element at each respective index of the tuple.

Parameters
tuplethe tuple to transform.
fnthe function to execute. Must accept a reference to each of the types in the tuple as a parameter and return a non-void value.
Exceptions
anyexception thrown by fn or by making a tuple from the results.

Variable Documentation

◆ aggregate_size_v

template<typename T >
constexpr std::size_t donut::reflection::aggregate_size_v = aggregate_size<T>::value
inlineconstexpr

The number of fields in a given aggregate type.

Template Parameters
Taggregate type to get the number of fields in.
Warning
Only sizes up to 26 are supported. If the template is instantiated with an aggregate type containing more than 26 fields, the program is ill-formed.