Closed TheNitesWhoSay closed 11 months ago
Auto-reflection of aggregates was released in 2.3.0, see documentation
This is only available when compiling against C++20 or higher and has many limitations that the macros do not as described here.
example1: https://godbolt.org/z/K75dhj5K4 example2: https://godbolt.org/z/GcKharfxj
struct Item
{
int id = 0;
std::string name {};
};
struct Collection
{
std::string description {};
std::vector<Item> items {};
};
int main()
{
Collection collection { "my collection", {{0, "first"}, {1, "second"}} };
std::cout << Json::pretty(collection);
}
Output:
{
"description": "my collection",
"items": [
{ "id": 0, "name": "first" },
{ "id": 1, "name": "second" }
]
}
As of C++20 it's possible to auto-magically get the names of the members of aggregates on all major compilers (in addition to auto-magically getting the values and types - which was already possible); integrate support for auto-reflecting aggregates when on C++20 & using them with the regular RareCpp interfaces.