It is a really strange issue: when I pass nlohmann::json to function it (json) becomes empty for an unknown reason. Moreover, if I just copy this function and rename it, everything ok.
Code below uses glm. It is in a separate header that is included in others.
template<typename T>
T import(const nlohmann::json &config) {
if (config.empty()) // true
return T();
T glmType;
auto array = reinterpret_cast<typename T::value_type *>(&glmType);
for (glm::length_t i = 0; i < sizeof(T) / sizeof(array[0]); i++)
array[i] = config[i];
return glmType;
}
Example:
json pos = {1, 2, 3};
assert(!pos.empty());
vec3 m_pos = import<vec3>(pos); // returns empty vector, but if I copy & rename function 'import' - everything will be ok
What is the expected behavior?
config mustn't be empty
And what is the actual behavior instead?
config for unknown reason becomes empty
Which compiler and operating system are you using?
- Compiler: GCC 10.2.0 / Clang 10.0.1
- Operating system: Linux (ArchLinux)
Which version of the library did you use?
It is a really strange issue: when I pass
nlohmann::jsonto function it (json) becomes empty for an unknown reason. Moreover, if I just copy this function and rename it, everything ok.Code below uses
glm. It is in a separate header that is included in others.Example:
json pos = {1, 2, 3}; assert(!pos.empty()); vec3 m_pos = import<vec3>(pos); // returns empty vector, but if I copy & rename function 'import' - everything will be okWhat is the expected behavior?
configmustn't be emptyAnd what is the actual behavior instead?
configfor unknown reason becomes emptyWhich compiler and operating system are you using?
Which version of the library did you use?
developbranch