Replies: 2 comments 18 replies
-
If you have C++20, please see You should be able to just do... std::vector<uint8_t> leverageVec = val.get<std::vector<uint8_t>>()); It is also possible prior to C++20, although a bit more busy work is needed. |
Beta Was this translation helpful? Give feedback.
17 replies
-
@lano1106 If your goal is to append to an existing container, you can do it like so: std::vector<uint32_t> array = {0, 0};
simdjson::padded_string json = R"({"data" : [1,2,3,4]})"_padded;
simdjson::ondemand::parser parser;
simdjson::ondemand::document d = parser.iterate(json);
d["data"].get<std::vector<uint32_t>>(array);
// array is now {0,0,1,2,3,4}
This works now with C++20. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I have returned to reading the classic from Scott Meyers: Effective STL.
In it, there is the item 5:
Prefer range member functions to their single-element counterpart.
It is a very convincing text that made me chase any code in my codebase using single-element insertion function to replace them with their range counterpart and I have stumbled into this:
I was so happy to find a prime candidate for the refactoring!
leverageVec.insert(std::cend(leverageVec), std::begin(levArray), std::end(levArray));
but the compiler did not let me do it:
beside, I am not sure if the simd proxy object would have performed the typecast correctly... since the one that is available is uint64_t...
(maybe boost::iterator_adapter could help... but this starts to be a complex solution for a simple task)
I have read in simdjson documentation that the number of element in a JSON array/object was expensive to compute, but I think that it might be possible to assign a output_iterator tag to the simdjson iterators so they can be used with STL containers...
Beta Was this translation helpful? Give feedback.
All reactions