Skip to content
/ rebind Public

🎲 Simple, compiler agnostic, C++20 reflection library (for aggregates and enums)

License

Notifications You must be signed in to change notification settings

Curve/rebind

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

76 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ“ƒ Description

Rebind is a simple, tiny C++20 reflection library for aggregates and enums.
This library is fully compiler agnostic as it figures out how to demangle given types at compile time.

πŸ“¦ Installation

  • Using CPM

    CPMFindPackage(
      NAME           rebind
      VERSION        3.0.0
      GIT_REPOSITORY "https://github.com/Curve/rebind"
    )
  • Using FetchContent

    include(FetchContent)
    
    FetchContent_Declare(rebind GIT_REPOSITORY "https://github.com/Curve/rebind" GIT_TAG v3.0.0)
    FetchContent_MakeAvailable(rebind)
    
    target_link_libraries(<target> cr::rebind)

πŸ“– Examples

expect(rebind::type_name<int> == "int");
expect(rebind::type_name<float> == "float");
expect(rebind::type_name<double> == "double");
constexpr auto values = rebind::enum_values<some_enum>;
expect(values.size() == 3);
expect(values.at(0).name == "a");
expect(values.at(0).value == some_enum::a);
expect(values.at(1).name == "b");
expect(values.at(1).value == some_enum::b);
expect(values.at(2).name == "c");
expect(values.at(2).value == some_enum::c);
simple instance{1, 2, 3, {true}};
const auto tuple = rebind::to_tuple(instance);
expect(std::tuple_size_v<decltype(tuple)> == 4);
expect(std::get<0>(tuple) == 1);
expect(std::get<1>(tuple) == 2);
expect(std::get<2>(tuple) == 3);
expect(std::get<3>(tuple).test);

πŸ§ͺ For more examples see tests

πŸ“‹ Documentation

template <typename T>
static constexpr auto type_name = /*...*/;

Returns: Human readable name of type T

template <auto T>
static constexpr auto nttp_name = /*...*/;

Returns: Human readable name of the given nttp T


template <typename T>
static constexpr auto arity = /*...*/;

Returns: Count of members of T

template <typename T>
constexpr auto to_tuple(T &value);

Returns: A tuple of references to all members of the given value


template <typename T>
static constexpr auto members = /*...*/;

Returns: A rebind::member object for each member present in the aggregate
Contains: The type, name and index

template <auto T>
static constexpr auto member_name = /*...*/;

Returns: The member name of the given member pointer


template <auto T>
static constexpr auto enum_name = /*...*/;

Returns: The name of the given enum value
Note: To get the name of an enum-type use rebind::type_name instead

template <typename T>
static constexpr auto enum_values = /*...*/;

Returns: All values of the given enum T (specialize rebind::search_min / rebind::search_max to tweak the search range)