Skip to content

throwing instead of assert for const& #2466

Answered by nlohmann
tawmoto asked this question in Q&A
Discussion options

You must be logged in to vote

The first snippet calls operator[] on a non-const json value, whereas the latter does so for a const json value. The behavior is different, just as you observed. Please use at if you want checked access which always throws in case of a missing key.

Documentation:

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by tawmoto
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants