benchmarks icon indicating copy to clipboard operation
benchmarks copied to clipboard

Update test_boost_json.cpp

Open beached opened this issue 3 years ago • 2 comments

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.

beached avatar Oct 31 '20 18:10 beached

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.

nuald avatar Oct 31 '20 18:10 nuald

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.

beached avatar Oct 31 '20 18:10 beached