Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update test_boost_json.cpp #282

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Update test_boost_json.cpp #282

wants to merge 1 commit into from

Conversation

beached
Copy link
Contributor

@beached beached commented Oct 31, 2020

This shows the Boost JSON in a better light and uses safer at( ) instead of operator[] that will insert if the member doesn't exist. At throws. It also uses a more idiomatic, for read only JSON, use of memory_resource similar to RapidJSON's pooled allocator.

This shows the Boost JSON in a better light and uses safer at( ) instead of operator[] that will insert if the member doesn't exist.  At throws.  It also uses a more idiomatic, for read only JSON, use of memory_resource similar to RapidJSON's pooled allocator.
@nuald
Copy link
Collaborator

nuald commented Oct 31, 2020

If you want safer operations, I'd recommend to change get_ to as_ too (i.e. use as_double instead of get_double). I deliberately used unsafe []-operator because we know ahead that the original JSON have the proper format, however in the real life I guess we want to use the safer operations as usually JSON values come across the trust boundaries.

@beached
Copy link
Contributor Author

beached commented Oct 31, 2020

At is also faster than operator[] when I was checking. It has a const overload too, so if the object is const it would still work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants