Add noexcept to JSON objects. (#7205)

This commit is contained in:
Jiaming Yuan
2021-09-07 13:56:48 +08:00
committed by GitHub
parent 3a4f51f39f
commit b12e7f7edd
3 changed files with 18 additions and 12 deletions

View File

@@ -169,10 +169,10 @@ Json& DummyJsonObject() {
}
// Json Object
JsonObject::JsonObject(JsonObject && that) :
JsonObject::JsonObject(JsonObject && that) noexcept :
Value(ValueKind::kObject), object_{std::move(that.object_)} {}
JsonObject::JsonObject(std::map<std::string, Json>&& object)
JsonObject::JsonObject(std::map<std::string, Json> &&object) noexcept
: Value(ValueKind::kObject), object_{std::move(object)} {}
Json& JsonObject::operator[](std::string const & key) {
@@ -233,7 +233,7 @@ void JsonString::Save(JsonWriter* writer) {
}
// Json Array
JsonArray::JsonArray(JsonArray && that) :
JsonArray::JsonArray(JsonArray && that) noexcept :
Value(ValueKind::kArray), vec_{std::move(that.vec_)} {}
Json& JsonArray::operator[](std::string const& ) {
@@ -406,7 +406,7 @@ Json JsonReader::Parse() {
Error("Unknown construct");
}
}
return Json();
return {};
}
Json JsonReader::Load() {
@@ -751,4 +751,9 @@ std::ostream &operator<<(std::ostream &os, StringView const v) {
}
return os;
}
static_assert(std::is_nothrow_move_constructible<Json>::value, "");
static_assert(std::is_nothrow_move_constructible<Object>::value, "");
static_assert(std::is_nothrow_move_constructible<Array>::value, "");
static_assert(std::is_nothrow_move_constructible<String>::value, "");
} // namespace xgboost