Horribly inconsistent behavior between const/non-const reference in operator [] () #289
Closed
Description
Things like
std::string tag;
try {
tag = json["tag"];
} catch (const std::domain_error &e) {
// handle it
}
works nicely and as expected. However, if json
is a const reference, the above code will fail by assertion. Why is it designed like so? Shouldn't it be better and more consistent to at least throw a domain_error
instead of fail by assertion? It took me more than one hour to debug this issue when I pass the above json by const reference to another function to extract data...