refl-cpp
refl::util Namespace Reference

Contains utility types and functions for working with those types. More...

Classes

struct  const_string
 
struct  type_list
 

Functions

constexpr const_string< 0 > make_const_string () noexcept
 
template<size_t N>
constexpr const_string< N - 1 > make_const_string (const char(&str)[N]) noexcept
 
template<size_t N, size_t M>
constexpr const_string< N+M > operator+ (const const_string< N > &a, const const_string< M > &b) noexcept
 
template<size_t N, size_t M>
constexpr const_string< N+M - 1 > operator+ (const const_string< N > &a, const char(&b)[M]) noexcept
 
template<size_t N, size_t M>
constexpr const_string< N+M - 1 > operator+ (const char(&a)[N], const const_string< M > &b) noexcept
 
template<size_t N, size_t M>
constexpr bool operator== (const const_string< N > &a, const const_string< M > &b) noexcept
 
template<size_t N, size_t M>
constexpr bool operator!= (const const_string< N > &a, const const_string< M > &b) noexcept
 
template<size_t N, size_t M>
constexpr bool operator== (const const_string< N > &a, const char(&b)[M]) noexcept
 
template<size_t N, size_t M>
constexpr bool operator!= (const const_string< N > &a, const char(&b)[M]) noexcept
 
template<size_t N, size_t M>
constexpr bool operator== (const char(&a)[N], const const_string< M > &b) noexcept
 
template<size_t N, size_t M>
constexpr bool operator!= (const char(&a)[N], const const_string< M > &b) noexcept
 
template<size_t N>
constexpr std::ostream & operator<< (std::ostream &os, const const_string< N > &str) noexcept
 
template<typename T = int, typename... Ts>
constexpr int ignore (Ts &&...) noexcept
 
template<typename T >
constexpr decltype(auto) identity (T &&t) noexcept
 
template<typename T >
constexpr const T & make_const (const T &value) noexcept
 
template<typename T >
constexpr const T & make_const (T &value) noexcept
 
template<typename T , typename... Ts>
constexpr std::array< T, sizeof...(Ts)> to_array (const std::tuple< Ts... > &tuple) noexcept
 
template<typename T >
constexpr std::array< T, 0 > to_array (const std::tuple<> &) noexcept
 
template<typename T , size_t N>
constexpr auto to_tuple (const std::array< T, N > &array) noexcept
 
template<typename F , typename... Ts>
constexpr auto map_to_tuple (type_list< Ts... > list, F &&f)
 
template<typename T , typename F , typename... Ts>
constexpr auto map_to_array (type_list< Ts... > list, F &&f)
 
template<typename F , typename... Ts>
constexpr void for_each (type_list< Ts... > list, F &&f)
 
template<typename R , typename F , typename... Ts>
constexpr R accumulate (type_list<>, F &&, R &&initial_value)
 
template<typename R , typename F , typename T , typename... Ts>
constexpr auto accumulate (type_list< T, Ts... >, F &&f, R &&initial_value)
 
template<typename F , typename... Ts>
constexpr size_t count_if (type_list< Ts... > list, F &&f)
 
template<typename F , typename... Ts>
constexpr auto filter (type_list< Ts... > list, F &&f)
 
template<typename F , typename... Ts>
constexpr auto find_first (type_list< Ts... > list, F &&f)
 
template<typename F , typename... Ts>
constexpr auto find_one (type_list< Ts... > list, F &&f)
 
template<typename F , typename... Ts>
constexpr auto contains (type_list< Ts... > list, F &&f)
 
template<typename... Ts, typename F >
constexpr auto apply (type_list< Ts... >, F &&f)
 
template<size_t N, typename... Ts>
constexpr auto & get (std::tuple< Ts... > &ts) noexcept
 
template<size_t N, typename... Ts>
constexpr const auto & get (const std::tuple< Ts... > &ts) noexcept
 
template<typename T , typename... Ts>
constexpr T & get (std::tuple< Ts... > &ts) noexcept
 
template<typename T , typename... Ts>
constexpr const T & get (const std::tuple< Ts... > &ts) noexcept
 
template<template< typename... > typename T, typename... Ts>
constexpr auto & get_instance (std::tuple< Ts... > &ts) noexcept
 
template<template< typename... > typename T, typename... Ts>
constexpr const auto & get_instance (const std::tuple< Ts... > &ts) noexcept
 

Detailed Description

Contains utility types and functions for working with those types.

Function Documentation

◆ accumulate() [1/2]

template<typename R , typename F , typename T , typename... Ts>
constexpr auto refl::util::accumulate ( type_list< T, Ts... >  ,
F &&  f,
R &&  initial_value 
)
constexpr

◆ accumulate() [2/2]

template<typename R , typename F , typename... Ts>
constexpr R refl::util::accumulate ( type_list<>  ,
F &&  ,
R &&  initial_value 
)
constexpr

◆ apply()

template<typename... Ts, typename F >
constexpr auto refl::util::apply ( type_list< Ts... >  ,
F &&  f 
)
constexpr

Applies a function to the elements of the type_list.

◆ contains()

template<typename F , typename... Ts>
constexpr auto refl::util::contains ( type_list< Ts... >  list,
F &&  f 
)
constexpr

Returns true if any item in the list matches the predicate. Calling f(Ts{})... should be valid in a constexpr context.

◆ count_if()

template<typename F , typename... Ts>
constexpr size_t refl::util::count_if ( type_list< Ts... >  list,
F &&  f 
)
constexpr

Counts the number of times the predicate F returns true. Note: Breaking changes introduced in v0.7.0: F can now no longer take a second index argument.

◆ filter()

template<typename F , typename... Ts>
constexpr auto refl::util::filter ( type_list< Ts... >  list,
F &&  f 
)
constexpr

Filters the list according to a constexpr predicate. Calling f(Ts{})... should be valid in a constexpr context.

◆ find_first()

template<typename F , typename... Ts>
constexpr auto refl::util::find_first ( type_list< Ts... >  list,
F &&  f 
)
constexpr

Returns the first instance that matches the constexpr predicate. Calling f(Ts{})... should be valid in a constexpr context.

◆ find_one()

template<typename F , typename... Ts>
constexpr auto refl::util::find_one ( type_list< Ts... >  list,
F &&  f 
)
constexpr

Returns the only instance that matches the constexpr predicate. If there is no match or multiple matches, fails with static_assert. Calling f(Ts{})... should be valid in a constexpr context.

◆ for_each()

template<typename F , typename... Ts>
constexpr void refl::util::for_each ( type_list< Ts... >  list,
F &&  f 
)
constexpr

Applies function F to each type in the type_list. F can optionally take an index of type size_t.

◆ get() [1/4]

template<size_t N, typename... Ts>
constexpr const auto& refl::util::get ( const std::tuple< Ts... > &  ts)
constexprnoexcept

A synonym for std::get<N>(tuple).

◆ get() [2/4]

template<typename T , typename... Ts>
constexpr const T& refl::util::get ( const std::tuple< Ts... > &  ts)
constexprnoexcept

A synonym for std::get<T>(tuple).

◆ get() [3/4]

template<size_t N, typename... Ts>
constexpr auto& refl::util::get ( std::tuple< Ts... > &  ts)
constexprnoexcept

A synonym for std::get<N>(tuple).

◆ get() [4/4]

template<typename T , typename... Ts>
constexpr T& refl::util::get ( std::tuple< Ts... > &  ts)
constexprnoexcept

A synonym for std::get<T>(tuple).

◆ get_instance() [1/2]

template<template< typename... > typename T, typename... Ts>
constexpr const auto& refl::util::get_instance ( const std::tuple< Ts... > &  ts)
constexprnoexcept

Returns the value of type U, where U is a template instance of T.

◆ get_instance() [2/2]

template<template< typename... > typename T, typename... Ts>
constexpr auto& refl::util::get_instance ( std::tuple< Ts... > &  ts)
constexprnoexcept

Returns the value of type U, where U is a template instance of T.

◆ identity()

template<typename T >
constexpr decltype(auto) refl::util::identity ( T &&  t)
constexprnoexcept

Returns the input paratemeter as-is. Useful for expanding variadic template lists when only one arguments is known to be present.

◆ ignore()

template<typename T = int, typename... Ts>
constexpr int refl::util::ignore ( Ts &&  ...)
constexprnoexcept

Ignores all parameters. Can take an optional template parameter specifying the return type of ignore. The return object is iniailized by {}.

◆ make_const() [1/2]

template<typename T >
constexpr const T& refl::util::make_const ( const T &  value)
constexprnoexcept

Adds const to the input reference.

◆ make_const() [2/2]

template<typename T >
constexpr const T& refl::util::make_const ( T &  value)
constexprnoexcept

Adds const to the input reference.

◆ make_const_string() [1/2]

constexpr const_string<0> refl::util::make_const_string ( )
constexprnoexcept

Creates an empty instance of const_string<N>

See also
refl::util::const_string

◆ make_const_string() [2/2]

template<size_t N>
constexpr const_string<N - 1> refl::util::make_const_string ( const char(&)  str[N])
constexprnoexcept

Creates an instance of const_string<N>

See also
refl::util::const_string

◆ map_to_array()

template<typename T , typename F , typename... Ts>
constexpr auto refl::util::map_to_array ( type_list< Ts... >  list,
F &&  f 
)
constexpr

Applies function F to each type in the type_list, aggregating the results in an array. F can optionally take an index of type size_t.

◆ map_to_tuple()

template<typename F , typename... Ts>
constexpr auto refl::util::map_to_tuple ( type_list< Ts... >  list,
F &&  f 
)
constexpr

Applies function F to each type in the type_list, aggregating the results in a tuple. F can optionally take an index of type size_t.

◆ operator!=() [1/3]

template<size_t N, size_t M>
constexpr bool refl::util::operator!= ( const char(&)  a[N],
const const_string< M > &  b 
)
constexprnoexcept

Compares a C-style string with a const_string for equality.

See also
refl::util::const_string

◆ operator!=() [2/3]

template<size_t N, size_t M>
constexpr bool refl::util::operator!= ( const const_string< N > &  a,
const char(&)  b[M] 
)
constexprnoexcept

Compares a const_string with a C-style string for equality.

See also
refl::util::const_string

◆ operator!=() [3/3]

template<size_t N, size_t M>
constexpr bool refl::util::operator!= ( const const_string< N > &  a,
const const_string< M > &  b 
)
constexprnoexcept

Compares two const_strings for equality.

See also
refl::util::const_string

◆ operator+() [1/3]

template<size_t N, size_t M>
constexpr const_string<N + M - 1> refl::util::operator+ ( const char(&)  a[N],
const const_string< M > &  b 
)
constexprnoexcept

Concatenates a C-style string with a const_string.

See also
refl::util::const_string

◆ operator+() [2/3]

template<size_t N, size_t M>
constexpr const_string<N + M - 1> refl::util::operator+ ( const const_string< N > &  a,
const char(&)  b[M] 
)
constexprnoexcept

Concatenates a const_string with a C-style string.

See also
refl::util::const_string

◆ operator+() [3/3]

template<size_t N, size_t M>
constexpr const_string<N + M> refl::util::operator+ ( const const_string< N > &  a,
const const_string< M > &  b 
)
constexprnoexcept

Concatenates two const_strings together.

See also
refl::util::const_string

◆ operator<<()

template<size_t N>
constexpr std::ostream& refl::util::operator<< ( std::ostream &  os,
const const_string< N > &  str 
)
constexprnoexcept

◆ operator==() [1/3]

template<size_t N, size_t M>
constexpr bool refl::util::operator== ( const char(&)  a[N],
const const_string< M > &  b 
)
constexprnoexcept

Compares a C-style string with a const_string for equality.

See also
refl::util::const_string

◆ operator==() [2/3]

template<size_t N, size_t M>
constexpr bool refl::util::operator== ( const const_string< N > &  a,
const char(&)  b[M] 
)
constexprnoexcept

Compares a const_string with a C-style string for equality.

See also
refl::util::const_string

◆ operator==() [3/3]

template<size_t N, size_t M>
constexpr bool refl::util::operator== ( const const_string< N > &  a,
const const_string< M > &  b 
)
constexprnoexcept

Compares two const_strings for equality.

See also
refl::util::const_string

◆ to_array() [1/2]

template<typename T , typename... Ts>
constexpr std::array<T, sizeof...(Ts)> refl::util::to_array ( const std::tuple< Ts... > &  tuple)
constexprnoexcept

Creates an array of type 'T' from the provided tuple. The common type T needs to be specified, in order to prevent any errors when using the overload taking an empty std::tuple (as there is no common type then).

◆ to_array() [2/2]

template<typename T >
constexpr std::array<T, 0> refl::util::to_array ( const std::tuple<> &  )
constexprnoexcept

Creates an empty array of type 'T.

◆ to_tuple()

template<typename T , size_t N>
constexpr auto refl::util::to_tuple ( const std::array< T, N > &  array)
constexprnoexcept

Creates a tuple from the provided array.