The following code
// note the *const*
const json object =
{
{"one", 1}, {"two", 2}, {"three", 2.9}
};
std::cout << object.size() << '\n';
std::cout << object["doh!"] << '\n'; // element not found
std::cout << object.size() << '\n'; // const object modified!
prints
Allowing a const object to change like this is not a good idea.
I think this is a bug: either the const overload of operator[] throws if the key cannot be found, or there is no such const overload (e.g. std::map does not have it).
The following code
prints
Allowing a const object to change like this is not a good idea.
I think this is a bug: either the const overload of
operator[]throws if the key cannot be found, or there is no such const overload (e.g. std::map does not have it).