Skip to content

Commit df2c791

Browse files
authored
forward mapped value in object::insert_or_assign
1 parent c527374 commit df2c791

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

include/boost/json/impl/object.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ insert_or_assign(
398398
key, key, static_cast<M&&>(m) );
399399
if( !result.second )
400400
{
401-
value(static_cast<M>(m), sp_).swap(
401+
value(static_cast<M&&>(m), sp_).swap(
402402
result.first->value());
403403
}
404404
return result;

test/object.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1201,6 +1201,17 @@ class object_test
12011201
{ "k3", 3 },
12021202
{ "k4", 2 }}));
12031203
}
1204+
1205+
// rvalue is moved, not copied, on the assign branch
1206+
{
1207+
object o = {
1208+
{ "k1", 1 },
1209+
{ "k2", { 1, 2, 3 } } };
1210+
value v = { 4, 5, 6 };
1211+
auto const d = v.as_array().data();
1212+
o.insert_or_assign("k2", std::move(v));
1213+
BOOST_TEST(o.at("k2").as_array().data() == d);
1214+
}
12041215
}
12051216

12061217
// emplace(key, arg)

0 commit comments

Comments
 (0)