-
Hi I have faced a very confusing behaviour from the json library, where depending on the way of instantiating a I have a json member I'd expect instead, when I don't use the assignment operator, what gets created is an array with one item, the item being this aforementioned object struct MyClass
{
std::unordered_map<std::string, MyType> data;
nlohmann::json json;
MyClass() : data{createData()}, json{data}
{
std::cout << json.dump(2);
json = data;
std::cout << json.dump(2)
}
}; The output for for the first cout is [
{
"key": { // value
}
}
] and for the 2nd cout it is {
"key": { // value
}
} which is what I expected. When I went through the code with a debugger it seemed like in the first case this constructor would be triggered first before going to basic_json template <
class... Args,
enable_if_t<std::is_constructible<value_type, Args...>::value, int> = 0 >
json_ref(Args && ... args)
: owned_value(std::forward<Args>(args)...)
{} whereas with the assignment operator, it would go straight to basic_json constructor Any ideas on what this is about, is this a bug? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
First entry of the FAQ: https://json.nlohmann.me/home/faq/ |
Beta Was this translation helpful? Give feedback.
First entry of the FAQ: https://json.nlohmann.me/home/faq/