Skip to content

Commit

Permalink
Correct a warning from cppcheck:
Browse files Browse the repository at this point in the history
binary_writer.hpp:869: (style) Consider using std::accumulate algorithm instead of a raw loop.

https://github.com/Xav83/nlohmann-json-cppcheck/commit/910a7d2b873dd7ae92ec81cced2bf73200ff4848/checks#step:5:107

Signed-off-by: Xav83 <[email protected]>
  • Loading branch information
Xav83 committed Sep 19, 2019
1 parent b54702e commit 708b16a
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions include/nlohmann/detail/output/binary_writer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -861,13 +861,10 @@ class binary_writer
*/
static std::size_t calc_bson_array_size(const typename BasicJsonType::array_t& value)
{
std::size_t embedded_document_size = 0ul;
std::size_t array_index = 0ul;

for (const auto& el : value)
const std::size_t embedded_document_size = std::accumulate(std::begin(value), std::end(value), [array_index = 0ul](std::size_t result, const auto& el)
{
embedded_document_size += calc_bson_element_size(std::to_string(array_index++), el);
}
return result + calc_bson_element_size(std::to_string(array_index++), el);
});

return sizeof(std::int32_t) + embedded_document_size + 1ul;
}
Expand Down

0 comments on commit 708b16a

Please sign in to comment.