Merge pull request #1034 from bluehero/master

Allow Swap with ValueType
This commit is contained in:
Milo Yip 2017-08-07 16:46:52 +08:00 committed by GitHub
commit f05edc9296
2 changed files with 12 additions and 1 deletions

View File

@ -2183,6 +2183,10 @@ public:
return *this;
}
// Allow Swap with ValueType.
// Refer to Effective C++ 3rd Edition/Item 33: Avoid hiding inherited names.
using ValueType::Swap;
//! free-standing swap function helper
/*!
Helper function to enable support for common swap implementation pattern based on \c std::swap:

View File

@ -300,7 +300,14 @@ TEST(Document, Swap) {
o.SetObject().AddMember("a", 1, a);
// Swap between Document and Value
// d1.Swap(o); // doesn't compile
d1.Swap(o);
EXPECT_TRUE(d1.IsObject());
EXPECT_TRUE(o.IsArray());
d1.Swap(o);
EXPECT_TRUE(d1.IsArray());
EXPECT_TRUE(o.IsObject());
o.Swap(d1);
EXPECT_TRUE(d1.IsObject());
EXPECT_TRUE(o.IsArray());