2
0
mirror of https://github.com/boostorg/json.git synced 2026-01-19 04:12:14 +00:00

string self-swap and self-move

This commit is contained in:
Dmitry Arkhipov
2022-08-28 08:46:43 +03:00
parent 154215306b
commit aaefd66bb1
3 changed files with 58 additions and 47 deletions

View File

@@ -539,6 +539,16 @@ public:
*s.storage() !=
*s2.storage());
});
// self
fail_loop([&](storage_ptr const& sp)
{
string s1(t.v1, sp);
string& s2 = s1;
s1 = std::move(s2);
BOOST_TEST(s1 == t.v1);
});
}
// operator=(char const*)
@@ -2515,35 +2525,39 @@ public:
{
test_vectors const t;
// swap
fail_loop([&](storage_ptr const& sp)
{
fail_loop([&](storage_ptr const& sp)
{
string s1(t.v1, sp);
string s2(t.v2, sp);
s1.swap(s2);
BOOST_TEST(s1 == t.v2);
BOOST_TEST(s2 == t.v1);
});
string s1(t.v1, sp);
string s2(t.v2, sp);
s1.swap(s2);
BOOST_TEST(s1 == t.v2);
BOOST_TEST(s2 == t.v1);
});
fail_loop([&](storage_ptr const& sp)
{
string s1(t.v1, sp);
string s2(t.v2, sp);
swap(s1, s2);
BOOST_TEST(s1 == t.v2);
BOOST_TEST(s2 == t.v1);
});
fail_loop([&](storage_ptr const& sp)
{
string s1(t.v1, sp);
string s2(t.v2, sp);
swap(s1, s2);
BOOST_TEST(s1 == t.v2);
BOOST_TEST(s2 == t.v1);
});
fail_loop([&](storage_ptr const& sp)
{
string s1(t.v1);
string s2(t.v2, sp);
s1.swap(s2);
BOOST_TEST(s1 == t.v2);
BOOST_TEST(s2 == t.v1);
});
}
fail_loop([&](storage_ptr const& sp)
{
string s1(t.v1);
string s2(t.v2, sp);
s1.swap(s2);
BOOST_TEST(s1 == t.v2);
BOOST_TEST(s2 == t.v1);
});
fail_loop([&](storage_ptr const& sp)
{
string s(t.v1, sp);
swap(s, s);
BOOST_TEST(s == t.v1);
});
}
void