Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Support for Inheritance and CRTPs #48

Open
RalphSteinhagen opened this issue Apr 22, 2024 · 1 comment
Open

Feature: Support for Inheritance and CRTPs #48

RalphSteinhagen opened this issue Apr 22, 2024 · 1 comment

Comments

@RalphSteinhagen
Copy link

@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!

@kris-jusiak
Copy link
Contributor

Thanks.

The inheritance is a bit tricky but I think it's possible to a certain degree at least.

Not sure, whether can be done with structure bindings, though 🤔 which is used for the member names reflection, is not required for member values.

https://godbolt.org/z/4n61vMaj4

Will give it a go, though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants