File tree Expand file tree Collapse file tree 1 file changed +21
-0
lines changed
Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -114,11 +114,25 @@ cppjson::Object& cppjson::JsonObject::As<cppjson::Object>() noexcept(false)
114114 return DangerousAs<cppjson::Object>();
115115}
116116
117+ template <>
118+ cppjson::Array& cppjson::JsonObject::As<cppjson::Array>() noexcept (false )
119+ {
120+ if (this ->_dataType == JsonType::Null)
121+ {
122+ this ->_dataType = JsonType::Array;
123+ return *new (this ->_dataStorage ) cppjson::Array{};
124+ }
125+
126+ if (this ->_dataType != JsonType::Array) throw std::logic_error (" Cannot convert this object to an array" );
127+ return DangerousAs<cppjson::Array>();
128+ }
129+
117130template <>
118131std::nullptr_t & cppjson::JsonObject::As<std::nullptr_t >() noexcept (false )
119132{
120133 if (std::exchange (this ->_dataType , JsonType::Null) == JsonType::Null) return DangerousAs<std::nullptr_t >();
121134
135+ Destroy ();
122136 return *new (this ->_dataStorage ) std::nullptr_t {};
123137}
124138
@@ -150,6 +164,13 @@ const cppjson::Object& cppjson::JsonObject::As<cppjson::Object>() const noexcept
150164 return DangerousAs<cppjson::Object>();
151165}
152166
167+ template <>
168+ const cppjson::Array& cppjson::JsonObject::As<cppjson::Array>() const noexcept (false )
169+ {
170+ if (this ->_dataType != JsonType::Array) throw std::logic_error (" Cannot convert this object to an Array" );
171+ return DangerousAs<cppjson::Array>();
172+ }
173+
153174template <>
154175const std::nullptr_t & cppjson::JsonObject::As<std::nullptr_t >() const noexcept (false )
155176{
You can’t perform that action at this time.
0 commit comments