template<class K, class V> inline void dynamic::insert(K&& key, V&& val) {
auto& obj = get<ObjectImpl>();
- auto rv = obj.insert(std::make_pair(std::forward<K>(key),
- std::forward<V>(val)));
- if (!rv.second) {
- // note, the second use of std:forward<V>(val) is only correct
- // if the first one did not result in a move. obj[key] = val
- // would be preferrable but doesn't compile because dynamic
- // is (intentionally) not default constructable
- rv.first->second = std::forward<V>(val);
- }
+ auto rv = obj.insert({ std::forward<K>(key), nullptr });
+ rv.first->second = std::forward<V>(val);
}
inline std::size_t dynamic::erase(dynamic const& key) {
EXPECT_EQ(d3.at("123"), 42);
EXPECT_EQ(d3.at(123), 321);
+ dynamic objInsert = folly::dynamic::object();
+ dynamic objA = folly::dynamic::object("1", "2");
+ dynamic objB = folly::dynamic::object("1", "2");
+
+ objInsert.insert("1", std::move(objA));
+ objInsert.insert("1", std::move(objB));
+
+ EXPECT_EQ(objInsert.find("1")->second.size(), 1);
+
// We don't allow objects as keys in objects.
EXPECT_ANY_THROW(newObject[d3] = 12);
}