Skip to content

Commit f05edc9

Browse files
authored
Merge pull request Tencent#1034 from bluehero/master
Allow Swap with ValueType
2 parents d630551 + f9004b9 commit f05edc9

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

include/rapidjson/document.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2183,6 +2183,10 @@ class GenericDocument : public GenericValue<Encoding, Allocator> {
21832183
return *this;
21842184
}
21852185

2186+
// Allow Swap with ValueType.
2187+
// Refer to Effective C++ 3rd Edition/Item 33: Avoid hiding inherited names.
2188+
using ValueType::Swap;
2189+
21862190
//! free-standing swap function helper
21872191
/*!
21882192
Helper function to enable support for common swap implementation pattern based on \c std::swap:

test/unittest/documenttest.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,14 @@ TEST(Document, Swap) {
300300
o.SetObject().AddMember("a", 1, a);
301301

302302
// Swap between Document and Value
303-
// d1.Swap(o); // doesn't compile
303+
d1.Swap(o);
304+
EXPECT_TRUE(d1.IsObject());
305+
EXPECT_TRUE(o.IsArray());
306+
307+
d1.Swap(o);
308+
EXPECT_TRUE(d1.IsArray());
309+
EXPECT_TRUE(o.IsObject());
310+
304311
o.Swap(d1);
305312
EXPECT_TRUE(d1.IsObject());
306313
EXPECT_TRUE(o.IsArray());

0 commit comments

Comments
 (0)