You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
These are symmetric to existing const typename object_t::value_type& overloads,
they bring the interface more in line with std::map (there are both insert(value_type const&) and insert(value_type &&) methods). The third overload allows rvalue json object to remain a temporary after operator+=.
Most importantly, these should allow for this simple code perform without copying:
I propose adding the following three overloads to
basic_json
:These are symmetric to existing
const typename object_t::value_type&
overloads,they bring the interface more in line with
std::map
(there are bothinsert(value_type const&)
andinsert(value_type &&)
methods). The third overload allows rvalue json object to remain a temporary afteroperator+=
.Most importantly, these should allow for this simple code perform without copying:
Please note that this code is not equivalent to
because sadly in C++
std::initializer_list
breaks perfect forwarding, and (possibly large) subobject is silently copied in this case.Without these overloads, I think that this could only be expressed (without runtime overhead) by
which is not very convenient.
Another alternative is to provide an explicit chainable method instead of (ab-)using
operator+=
. This could lead to cleaner code like:This method should return an rvalue reference when called on an rvalue object, too.
The text was updated successfully, but these errors were encountered: