Simplify exchange implementation for pre-C++11

This commit is contained in:
Glen Fernandes
2018-07-09 08:48:40 -04:00
parent 75ae238d0c
commit 19ec659a91
3 changed files with 58 additions and 21 deletions

View File

@@ -59,10 +59,37 @@ void test2()
BOOST_TEST(x.i() == 2);
}
class C3 {
public:
explicit C3(int i)
: i_(i) { }
C3(C3&& c)
: i_(c.i_) { }
C3& operator=(C1&& c) {
i_ = c.i();
return *this;
}
int i() const {
return i_;
}
private:
C3(const C3&);
C3& operator=(const C3&);
int i_;
};
void test3()
{
C3 x(1);
BOOST_TEST(boost::exchange(x, C1(2)).i() == 1);
BOOST_TEST(x.i() == 2);
}
int main()
{
test1();
test2();
test3();
return boost::report_errors();
}
#else