Closed
Description
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
3
null
4
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).