Skip to content

Feature: Support for Inheritance and CRTPs #48

@RalphSteinhagen

Description

@RalphSteinhagen

@kris-jusiak again a very superb library. Kudos 👍

What would it take to enable support for inherited classes and CTRPs (see compiler-explorer example):

#include <https://raw.githubusercontent.com/boost-ext/reflect/main/reflect>
#include <print>
#include <string>
#include <string_view>
#include <type_traits>

template <typename Derived>
struct Base {
 float d = 3.141f;
};

template<typename T>
struct Test : public Base<Test<T>> {
    T a = 42;
    float b = 43.f;
    std::string c = "Hello World!";
};

int main() {
    Test<int> s{};

    reflect::for_each([&](auto I) {
        const auto value = reflect::get<I>(s);
        constexpr std::string_view class_name(reflect::type_name(s));
        constexpr std::string_view name = reflect::member_name<I>(s);
        constexpr std::string_view type_name = reflect::type_name(reflect::get<I>(s));
        std::print("reflect:  {}.{} {} = {}\n", class_name, type_name, name, value);
    }, s);
}

Keep up the good work!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions