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

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