-
Notifications
You must be signed in to change notification settings - Fork 25
Description
I've been using this library, and I think it's fantastic. Well done!
It looks like things started when this was posted: [C++20] 60 LOC constexpr get_name for members / no ifdefs / clang,gcc,msvc .
I've been playing a bit with this example and realized it's possible to get structs name even if a user defined constructor exists.
It's also possible to iterate over the members of a struct that has a user defined constructor.
So far, getting names and values of a struct's members works if a user defined constructor exists.
Of course, it only works if:
- A default constructor exists, e.g.
foo() = default;. - A constructor with an argument for each struct's member exists.
Second point means:
struct Point
{
Point() {}
Point(int x_, int y_) : x{x_}, y{y_} {}
int x;
int y;
};If I have both constructors, I can do something like:
struct Point
{
Point() {}
Point(int x_, int y_, int z_) : x{x_}, y{y_}, z{z_} {}
Point(int x_, int y_) : x{x_}, y{y_}, z{0} {}
int x;
int y;
int z;
};And it works, I can iterate over all three members and get their names and values.
Of course, this means that the is_aggregate_v constraint no longer applies, and that the first two constructors need to exist, otherwise it fails to compile.
Do you think that's something that could be added to reflect to make it work on structs that have user defined constructors?