conststr 0.2.1
Loading...
Searching...
No Matches
Classes | Namespaces | Typedefs | Functions | Variables
reflect.hpp File Reference

Header file of comiple-time reflection support. More...

#include <functional>
#include "conststr.hpp"

Go to the source code of this file.

Classes

struct  reflect::any_type
 Type that can be implicitly converted to any type. More...
 
struct  reflect::cptr< T >
 Wrapper of pointer type. More...
 

Namespaces

namespace  reflect
 Compile-time reflection for aggregate types.
 

Typedefs

template<typename T , std::size_t N>
using reflect::type_of = std::remove_cvref_t< std::tuple_element_t< N, decltype(to_tuple(fake_obj< T >))> >
 Type of N-th member of a default-constructible aggregate type T. More...
 
template<typename T , conststr::cstr Name>
using reflect::type_of_member = type_of< T, index_of< T, Name > >
 Get the type of the member by its name. More...
 

Functions

template<typename T , typename... Args>
requires (std::is_aggregate_v<std::remove_cvref_t<T>> && std::is_default_constructible_v<std::remove_cvref_t<T>>)
consteval std::size_t reflect::number_of_members_impl ()
 Internal implementation of number_of_members. Get The number of a default-constructible aggregate type's members. More...
 
template<class T , std::size_t N = number_of_members<T>>
requires (N <= 128)
constexpr decltype(auto) reflect::to_tuple (T &&t)
 Convert a value of type T to a tuple containing references to all its members. More...
 
template<typename T , std::size_t N>
consteval auto reflect::cptr_of_member ()
 Get the pointer of the N-th member as a constexpr value. More...
 
template<cptr Ptr>
consteval auto reflect::pretty_name ()
 Core function to get member name via compiler built-in macro. More...
 
template<conststr::cstr Name>
consteval auto reflect::basename_of_impl ()
 Internal implementation of basename_of. get the Base name of a full qualified name. More...
 
template<cptr Ptr>
consteval auto reflect::name_of_ptr_impl ()
 Internal implementation of name_of_ptr. Extract the real name from the output of pretty_name(). More...
 
template<typename T , conststr::cstr Name, std::size_t SrchIdx>
requires (number_of_members<T> > SrchIdx)
constexpr size_t reflect::index_of_impl ()
 Internal implementation of index_of. Get the index of the member by its name. More...
 
template<std::size_t N, typename T >
constexpr decltype(auto) reflect::member_of (T &&t)
 Get member reference of object t. More...
 
template<conststr::cstr Name, typename T >
requires std::same_as<typename decltype(Name)::value_type, char>
constexpr decltype(auto) reflect::member_of (T &&t)
 Get member reference of object t via member's name. More...
 

Variables

template<typename T >
const T reflect::fake_obj
 An object of T that can be used in constant context without really construct it. More...
 
template<typename T >
constexpr std::size_t reflect::number_of_members = number_of_members_impl<T>()
 The number of a default-constructible aggregate type's members. More...
 
template<conststr::cstr Name>
constexpr auto reflect::basename_of = basename_of_impl<Name>()
 Base name of a full qualified name. More...
 
template<cptr Ptr>
constexpr auto reflect::name_of_ptr = name_of_ptr_impl<Ptr>()
 Get the variable or class member name from its pointer. More...
 
template<typename T , std::size_t N>
constexpr auto reflect::name_of = name_of_ptr<cptr_of_member<T, N>()>
 Name of N-th member of a default-constructible aggregate type T. More...
 
template<typename T , conststr::cstr Name>
constexpr size_t reflect::index_of = index_of_impl<T, Name, 0>()
 Get the index of the member by its name. More...
 

Detailed Description

Header file of comiple-time reflection support.