This commit is contained in:
nlohmann committed 2026-11-12 11:46:38 +00:00
1 parent 8ddeea7128
commit 5097c20962
516 files changed
+7306 -5984

No files matched your search

+4
View File
@@ -24,6 +24,10 @@ void push_back(initializer_list_t init);
`init` is converted into an object element and added using `push_back(const typename object_t::value_type&)`. Otherwise, `init` is converted to a JSON value and added using `push_back(basic_json&&)`.
Single braced JSON value
For a call such as `arr.push_back({obj})`, where the initializer list contains a single JSON value `obj`, compilers may disagree unless [`JSON_BRACE_INIT_COPY_SEMANTICS`](https://json.nlohmann.me/api/macros/json_brace_init_copy_semantics/index.md) is defined to `1`: GCC, for example, selects this overload and appends a single-element array `[obj]`, whereas Clang selects the `basic_json` overload and appends a copy of `obj`. With the macro, GCC and Clang both append a copy of `obj`. To get a portable result without the macro, write `arr.push_back(obj)` to append a copy, or `arr.push_back(json::array({obj}))` to append a single-element array.
## Iterator invalidation
For all cases where an element is added to an **array**, a reallocation can happen, in which case all iterators (including the [`end()`](https://json.nlohmann.me/api/basic_json/end/index.md) iterator) and all references to the elements are invalidated. Otherwise, only the [`end()`](https://json.nlohmann.me/api/basic_json/end/index.md) iterator is invalidated.