Files
json/single_include/nlohmann
Niels Lohmann 4503e5d9bc Copy instead of move when converting an rvalue non-owning range
Converting an rvalue array-like or object-like container to JSON moves its
elements since the rvalue to_json overloads were added. The check only looked
at the value category, so non-owning ranges (gsl::span, absl::Span, span
backports, iterator ranges), which are usually passed by value, had the
elements of the storage they refer to moved out:

    std::vector<std::string> v = {...};
    json j = make_span(v); // v's strings were left empty

Move only from containers that own their elements, detected by deep
constness: the elements of a const std::vector or std::map are const, while a
const span still gives mutable elements. The rvalue overloads still take
every rvalue container and copy the elements of the others, as in 3.12.0;
this also keeps ranges that can only be iterated when not const working.

Signed-off-by: Niels Lohmann <mail@nlohmann.me>
2026-11-16 07:16:10 +01:00
..