Skip to content

Commit c75f4d9

Browse files
committed
Making web::json::object have public copy constructor.
1 parent ba245ec commit c75f4d9

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

Release/include/cpprest/json.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -921,8 +921,6 @@ namespace json
921921
sort(m_elements.begin(), m_elements.end(), compare_pairs);
922922
}
923923
}
924-
object(const object& obj); // non copyable
925-
object& operator=(const object& obj); // non copyable
926924

927925
public:
928926
/// <summary>
@@ -1177,7 +1175,7 @@ namespace json
11771175
}
11781176

11791177
storage_type m_elements;
1180-
const bool m_keep_order;
1178+
bool m_keep_order;
11811179
friend class details::_Object;
11821180

11831181
template<typename CharType> friend class json::details::JSON_Parser;

Release/tests/functional/json/to_as_and_operators_tests.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,33 @@ TEST(as_string)
184184
VERIFY_ARE_EQUAL(wdata, str.as_string());
185185
}
186186

187+
TEST(as_copy_constructor)
188+
{
189+
auto arr = json::value::array();
190+
arr[0] = json::value::number(44);
191+
arr[1] = json::value::string(U("abc"));
192+
json::array arrCopy = arr.as_array();
193+
VERIFY_ARE_EQUAL(2, arrCopy.size());
194+
VERIFY_ARE_EQUAL(2, arr.size());
195+
VERIFY_ARE_EQUAL(44, arrCopy[0].as_integer());
196+
VERIFY_ARE_EQUAL(U("abc"), arrCopy[1].as_string());
197+
VERIFY_ARE_EQUAL(44, arr[0].as_integer());
198+
VERIFY_ARE_EQUAL(U("abc"), arr[1].as_string());
199+
200+
auto obj = json::value::object();
201+
obj[U("abc")] = json::value::number(123);
202+
json::object objCopy = obj.as_object();
203+
VERIFY_ARE_EQUAL(1, objCopy.size());
204+
VERIFY_ARE_EQUAL(1, obj.size());
205+
VERIFY_ARE_EQUAL(123, objCopy[U("abc")].as_integer());
206+
VERIFY_ARE_EQUAL(123, obj[U("abc")].as_integer());
207+
208+
auto num = json::value::number(44);
209+
json::number numCopy = num.as_number();
210+
VERIFY_ARE_EQUAL(44, num.as_integer());
211+
VERIFY_ARE_EQUAL(44, numCopy.to_int32());
212+
}
213+
187214
TEST(as_bool_as_double_as_string)
188215
{
189216
utility::stringstream_t ss1;

0 commit comments

Comments
 (0)