inline int64_t& dynamic::getInt() & { return get<int64_t>(); }
inline bool& dynamic::getBool() & { return get<bool>(); }
-inline std::string dynamic::getString()&& {
+inline std::string&& dynamic::getString()&& {
return std::move(get<std::string>());
}
inline double dynamic::getDouble() && { return get<double>(); }
return at(idx);
}
-inline dynamic dynamic::operator[](dynamic const& idx) && {
+inline dynamic&& dynamic::operator[](dynamic const& idx) && {
return std::move((*this)[idx]);
}
return const_cast<dynamic&>(const_cast<dynamic const*>(this)->at(idx));
}
-inline dynamic dynamic::at(dynamic const& idx) && {
+inline dynamic&& dynamic::at(dynamic const& idx) && {
return std::move(at(idx));
}
double& getDouble() &;
int64_t& getInt() &;
bool& getBool() &;
- std::string getString() &&;
+ std::string&& getString() &&;
double getDouble() &&;
int64_t getInt() &&;
bool getBool() &&;
*/
dynamic const& at(dynamic const&) const&;
dynamic& at(dynamic const&) &;
- dynamic at(dynamic const&) &&;
+ dynamic&& at(dynamic const&) &&;
/*
* Like 'at', above, except it returns either a pointer to the contained
*/
dynamic& operator[](dynamic const&) &;
dynamic const& operator[](dynamic const&) const&;
- dynamic operator[](dynamic const&) &&;
+ dynamic&& operator[](dynamic const&) &&;
/*
* Only defined for objects, throws TypeError otherwise.
EXPECT_EQ(s + " hello", d.getString());
EXPECT_EQ(s, std::move(m).getString());
+ EXPECT_EQ(s, m.getString());
+ auto moved = std::move(m).getString();
+ EXPECT_EQ(s, moved);
EXPECT_NE(dynamic(s), m);
}
EXPECT_EQ(dynamic(make_long_string() + " hello"), dd.at("key1"));
EXPECT_EQ(dynamic(make_long_string() + " hello"), dd.at("key1"));
- EXPECT_EQ(ds, std::move(md).at("key1"));
+ EXPECT_EQ(ds, std::move(md).at("key1")); // move available, but not performed
+ EXPECT_EQ(ds, md.at("key1"));
+ dynamic moved = std::move(md).at("key1"); // move performed
+ EXPECT_EQ(ds, moved);
EXPECT_NE(ds, md.at("key1"));
}
EXPECT_EQ(dynamic(make_long_string() + " hello"), dd["key1"]);
EXPECT_EQ(dynamic(make_long_string() + " hello"), dd["key1"]);
- EXPECT_EQ(ds, std::move(md)["key1"]);
+ EXPECT_EQ(ds, std::move(md)["key1"]); // move available, but not performed
+ EXPECT_EQ(ds, md["key1"]);
+ dynamic moved = std::move(md)["key1"]; // move performed
+ EXPECT_EQ(ds, moved);
EXPECT_NE(ds, md["key1"]);
}