Hi @veselink1
First of all, I would like to thank you for developing such an amazing library for C++. It has helped us a lot.
While I was developing functionalities based on refl-cpp, I noticed some very strange behavior and I can't figure out where it comes from.
Below are some code to reproduce the bheavior. I was trying to write an "recursiveForEach" function for nested reflected types. The code below has nothing to do with recursion as I have tried to minimize the code.
Link to goldbolt
I have wrriten 3 wrappers around the for each utility from refl.
The first one takes an instance of the object but uses refl::reflect<T>() to get the descriptor.
The second one takes an instance of the object but uses refl::reflect(const T&) to get the descriptor.
The third one does not take an instance of the object but instead, it iterate through the members using refl::reflect<T>() to get the descriptor.
In theory, the three usage of reflect should hehave exactly the same but the first one will result in empty members. The third one also uses refl::reflect<T>() but different from the first funtion, it works.
When you run this code, you should see the following output
for each with reflct<T>()
for each with reflct(const &T)
1,2,
for each discriptor without passing an instance
a,b,
end of program
I have tried this on gcc 9.4, 10.2, 10.3, all resulted in the same behavior.
Hi @veselink1 First of all, I would like to thank you for developing such an amazing library for C++. It has helped us a lot. While I was developing functionalities based on refl-cpp, I noticed some very strange behavior and I can't figure out where it comes from. Below are some code to reproduce the bheavior. I was trying to write an "recursiveForEach" function for nested reflected types. The code below has nothing to do with recursion as I have tried to minimize the code. Link to goldbolt
Here's the code itself.
I have wrriten 3 wrappers around the for each utility from refl. The first one takes an instance of the object but uses
refl::reflect<T>()
to get the descriptor. The second one takes an instance of the object but usesrefl::reflect(const T&)
to get the descriptor. The third one does not take an instance of the object but instead, it iterate through the members usingrefl::reflect<T>()
to get the descriptor. In theory, the three usage of reflect should hehave exactly the same but the first one will result in empty members. The third one also usesrefl::reflect<T>()
but different from the first funtion, it works.When you run this code, you should see the following output
I have tried this on gcc 9.4, 10.2, 10.3, all resulted in the same behavior.