Closed Alecsou closed 1 month ago
Thank you for reporting this. I will take a Look.
My suspicion is that's it isn't the the depth of the struct but the total number of fields that's the problem here. It may be due to std::tuple. I will take a closer look and let you know.
Hi @Alecsou , I was able to reproduce the problem. It appears to be an MSVC-only problem, though, all other compilers work fine:
https://github.com/getml/reflect-cpp/pull/147
I will try to find a fix for this.
Hi, quick update :
This problem is a more broad one, the library fails to deal with "big" classes in multiple cases with always the same error. I for example added an operator using the library in a class with a lot (30~ double) of fields and it failed compilation also.
double operator [] (std::string field) {
std::map m = std::map < std::string, double>();
const auto view = rfl::to_view(*this);
view.apply([](const auto& f) {
if (f.name() == field) {
return (double)f.value();
}
});
}
This makes the library completely unusable under MSVC right now... Hope this can be solved, as this library seems really promising to say the least !
Yes, that is what I thought. It's not the depth, it's the number of fields.
I suspect that the issue is std::tuple and I am afraid that I might have to implement my own version. I am on this.
I was about to create an issue, but I am facing the same one as described here. Hope this gets resolved soon, as I wanted to implement reflect-cpp into my project.
@RampantDespair , I am on it.
I have conducted a couple of experiments. I am afraid the issue is with the way std::tuple is implemented in the standard library in combination with MSVC compiler restrictions and I will probably have to implement my own version. It will take me a couple of days, but I think I might get this resolved by next week.
@Alecsou and @RampantDespair , good news: My initial hypothesis turned out to be true. It was indeed std::tuple that was the problem here. I have now found a tuple-free way of getting the field names out of the structs:
https://github.com/getml/reflect-cpp/pull/160
As you can see, the test compiles even on MSVC. This still needs some code beautification, but the proof-of-concept is there. I am confident I will be able to merge this over the next couple of days.
@liuzicheng1987 That's great news! I'm eager to try it it out
@RampantDespair and @Alecsou , the issue is resolved: 9c9eceab929a65aa9a7c846940ba60675fd243b5
Expected Behavior
No compilation error
Current Behavior
error C1054: compiler limit: initializers nested too deeply
How to Reproduce
main.cpp
DeepClass.h
LowHeightClass.h
The error is raised in
rfl\internal\get_field_names.hpp(142,39)
.I was expecting it to work since the data structure is not that deep (in this example, 3 classes deep) but still doesn't compile.
Context (Environment)
Visual Studio 2022 (v143) 17.10.0 Windows 10.0 C++20