Several from_json() overload pairs in from_json.hpp were copies of each
other, so a fix has to be applied twice (as #5681 already does):
- from_json(..., std::map&) and from_json(..., std::unordered_map&) for
non-string keys had identical 16-line bodies: array check, m.clear(),
pair check loop, m.emplace(...). Route both through a new
from_json_pair_array_to_map(j, m) helper.
- The from_json_array_impl priority_tag<1> and priority_tag<0> fallbacks
ran the same std::transform/std::inserter loop, differing only in
ret.reserve(j.size()). Merge them into one body and, modeled on the
existing from_json_object_reserve, add a from_json_array_reserve pair
so the reserve() call is only made for ConstructibleArrayType that
support it.
Error ids (type_error.302), messages, diagnostic paths ((at(0)/at(1))
and behavior for types with/without reserve() are unchanged; only the
duplication is removed.
Public API: no change.
Overlaps #5681, which changes the "&j" to "&p" line in both map bodies;
the shared helper here should make that a one-line change instead of two
on rebase.
Signed-off-by: Niels Lohmann <mail@nlohmann.me>
#5708 item 5