Utilities for template and preprocessor metaprogramming. More...
Classes | |
struct | aurora::Type< T > |
Simple type wrapper, can be used for overload resolution. More... | |
struct | aurora::Int< N > |
Simple integer wrapper, can be used for overload resolution. More... | |
struct | aurora::FunctionResult< Signature > |
Find out the return type of a function. More... | |
struct | aurora::FunctionParam< Signature, N > |
Find out the N-th parameter type of a function. More... | |
struct | aurora::FunctionArity< Signature > |
Find out the number of parameters of a function. More... | |
struct | aurora::Typelist< Ts > |
Class template to store a list of types. More... | |
struct | aurora::TypelistAt< Types, Index > |
Random access to type. More... | |
struct | aurora::TypelistFind< Types, Searched > |
Find position of type in typelist. More... | |
struct | aurora::TypelistCat< LhsTypelist, RhsTypelist > |
Concatenate two typelists. More... | |
struct | aurora::TypelistContains< Typelist1, T > |
Check if type is part of typelist. More... | |
Macros | |
#define | AURORA_PP_LIMIT 5 |
Limit for preprocessor metaprogramming arguments. More... | |
#define | AURORA_PP_CAT(a, b) |
Concatenate two expressions (evaluated ## operator) More... | |
#define | AURORA_PP_STRINGIZE(a) |
Convert expression to string (evaluated # operator) More... | |
#define | AURORA_PP_IF(condition, trueCase, falseCase) |
Conditional evaluation. More... | |
#define | AURORA_PP_ENUMERATE(n, macro) |
Apply a macro repeated times. More... | |
#define | AURORA_PP_ENUMERATE_COMMA(n, macro) |
Apply a macro repeated times, comma-separated. More... | |
#define | AURORA_PP_COMMA_IF(n) |
Comma if non-zero argument. More... | |
#define | AURORA_PP_AT(size, n, tuple) |
Access element of tuple. More... | |
#define | AURORA_PP_FOREACH(macro, tuple) |
Apply macro for each element in tuple. More... | |
#define | AURORA_PP_FOREACH_DATA(macro, tuple, data) |
Apply macro for each element in tuple, with additional argument. More... | |
#define | AURORA_PP_POSITIVE_SIZE(tuple) |
Size of a non-empty preprocessor tuple. More... | |
#define | AURORA_PP_SIZE(tuple) |
Size of a preprocessor tuple. More... | |
#define | AURORA_ENABLE_IF(...) , typename std::enable_if<__VA_ARGS__>::type* = nullptr |
SFINAE Enable If Macro for parameter lists. More... | |
#define | AURORA_REQUIRE_COMPLETE_TYPE(Type) |
Macro to ensure complete type. More... | |
#define | AURORA_AUTO_RETURN(...) decltype(__VA_ARGS__) { return (__VA_ARGS__); } |
Function declaration with inferred return type. More... | |
Functions | |
template<typename Result , typename Tuple > | |
Result * | aurora::dynamicGet (Tuple &t, std::size_t i) |
Access tuple with dynamic index. More... | |
template<typename Transformer , typename SrcTuple > | |
auto | aurora::tupleTransform (const SrcTuple &src) -> InferredReturnType Transformer, std::tuple_size< SrcTuple >::value >::apply(src)) template< typename Tuple > auto tupleFront(Tuple &&t) -> InferredReturnType template< typename Tuple > auto tupleBack(Tuple &&t) -> InferredReturnType template< typename T, typename...Us > T &tupleGet(std::tuple< Us... > &tuple) |
Transform one tuple into another. More... | |
template<typename... Ts, typename Function > | |
void | aurora::foreach (Function &&fn) |
Apply function for each type in variadic parameter pack. More... | |
template<typename... Ts, typename Function > | |
void | aurora::foreach (Function &&fn, Ts &&...args) |
Apply function for each value in variadic parameter pack. More... | |
Utilities for template and preprocessor metaprogramming.
#define AURORA_AUTO_RETURN | ( | ... | ) | decltype(__VA_ARGS__) { return (__VA_ARGS__); } |
Function declaration with inferred return type.
Based on the C++11 trailing return types feature. Since a lot of functions that benefit from trailing return types must repeat the return type by means of decltype, this macro has been written to avoid the code duplication.
Example:
#define AURORA_ENABLE_IF | ( | ... | ) | , typename std::enable_if<__VA_ARGS__>::type* = nullptr |
#define AURORA_PP_AT | ( | size, | |
n, | |||
tuple | |||
) |
Access element of tuple.
size | Size of the tuple. Can be inferred using AURORA_PP_SIZE. |
n | Index of the element to access, 0 <= n < size |
tuple | Preprocessor tuple such as (a, b, c) |
Returns the n-th element of a tuple.
#define AURORA_PP_CAT | ( | a, | |
b | |||
) |
Concatenate two expressions (evaluated ## operator)
This macro does the same as the built-in ## preprocessor operator, however the arguments are expanded before concatenation.
#define AURORA_PP_COMMA_IF | ( | n | ) |
Comma if non-zero argument.
Evaluates to a comma if n is positive, and to nothing if n is zero.
#define AURORA_PP_ENUMERATE | ( | n, | |
macro | |||
) |
Apply a macro repeated times.
n | Number of invocations |
macro | Macro with signature macro(index) , where index is a number from 0 to n-1. |
Invokes the macro n times, passing it the indices from 0 to n-1 in this order.
#define AURORA_PP_ENUMERATE_COMMA | ( | n, | |
macro | |||
) |
Apply a macro repeated times, comma-separated.
n | Number of invocations |
macro | Macro with signature macro(index) , where index is a number from 0 to n-1. |
Invokes the macro n times, passing it the indices from 0 to n-1 in this order. Puts a comma between each invocation.
#define AURORA_PP_FOREACH | ( | macro, | |
tuple | |||
) |
Apply macro for each element in tuple.
macro | Macro with signature macro(value, index) , where value is the current element of the tuple and index is its index as a number from 0 to n-1. |
tuple | Parenthesized tuple, such as (a, b, c). May be empty. |
Applies a macro repeated times, passing it every element in a tuple.
#define AURORA_PP_FOREACH_DATA | ( | macro, | |
tuple, | |||
data | |||
) |
Apply macro for each element in tuple, with additional argument.
macro | Macro with signature macro(value, index, data) , where value is the current element of the tuple, index is its index as a number from 0 to n-1, and data is the additional argument being forwarded. |
tuple | Parenthesized tuple, such as (a, b, c). May be empty. |
data | Additional argument to forward. |
Applies a macro repeated times, passing it every element in a tuple. Additional data can be specified that doesn't affect the repetition, but is passed to each macro invocation as an additional argument.
#define AURORA_PP_IF | ( | condition, | |
trueCase, | |||
falseCase | |||
) |
Conditional evaluation.
If condition
evaluates to a positive number, then the expression will be replaced with trueCase
. If condition
is zero, then it will be falseCase
.
When you use function style macros for trueCase
and falseCase
, put the argument list after the invocation, i.e. AURORA_PP_IF(...)(args)
#define AURORA_PP_LIMIT 5 |
Limit for preprocessor metaprogramming arguments.
This number is the maximum size of preprocessor tuples and the highest number that can be passed to repetition macros.
#define AURORA_PP_POSITIVE_SIZE | ( | tuple | ) |
Size of a non-empty preprocessor tuple.
tuple | Preprocessor tuple such as (a, b, c), of which the size is inferred. |
Returns a non-zero number of elements in a tuple. Use this macro whenever you are sure that a tuple will not be empty.
#define AURORA_PP_SIZE | ( | tuple | ) |
Size of a preprocessor tuple.
tuple | Preprocessor tuple such as (a, b, c), of which the size is inferred. |
Returns the number of elements in a tuple. The size inference may fail in special cases with nested macros. If you are sure that a tuple is non-empty, use AURORA_PP_POSITIVE_SIZE instead, which is simpler and more robust.
#define AURORA_PP_STRINGIZE | ( | a | ) |
Convert expression to string (evaluated # operator)
This macro does the same as the built-in # preprocessor operator, however the argument is expanded before stringization.
#define AURORA_REQUIRE_COMPLETE_TYPE | ( | Type | ) |
Result* aurora::dynamicGet | ( | Tuple & | t, |
std::size_t | i | ||
) |
Access tuple with dynamic index.
Usually, you can only access std::tuple by means of std::get<N>, where N must be a constant expression. This function allows you to pass a dynamic index.
Result | A type to which every element in the tuple is convertible, e.g. pointer to common base class. |
t | The tuple of which you want to get an element |
i | The index of the element, can be known at runtime |
void aurora::foreach | ( | Function && | fn | ) |
Apply function for each type in variadic parameter pack.
Ts | List of types to iterate through. Can also be a single type of aurora::Typelist<...>. |
fn | Function object with a member function template void operator() (). |
For each type T
in Ts
, the fn's
operator() is called with explicit template argument T
. Example:
void aurora::foreach | ( | Function && | fn, |
Ts &&... | args | ||
) |
Apply function for each value in variadic parameter pack.
fn | Function object with a member function template void operator() (T& value), or C++14 generic lambda. The parameter must be compatible to type T , however pass by value or by (const) (lvalue|rvalue) reference is allowed. |
args | Arguments to iterate through. |
For each argument arg
in args
, the expression fn(arg) is evaluated. Example:
auto aurora::tupleTransform | ( | const SrcTuple & | src | ) | -> InferredReturnType Transformer, std::tuple_size<SrcTuple>::value>::apply(src) ) template <typename Tuple> auto tupleFront(Tuple&& t) -> InferredReturnType template <typename Tuple> auto tupleBack(Tuple&& t) -> InferredReturnType template <typename T, typename... Us> T& tupleGet(std::tuple<Us...>& tuple) |
Transform one tuple into another.
Transforms each element of a tuple using a given function.
Transformer | Class that has a method static R transform(T element) that takes an element of the source tuple and returns a corresponding value of the new tuple. transform() can be a function template to account for different element types. |
src | Input tuple being transformed. |
src
, but possibly different element types.Example code: