proper swap and move operations on swap oss

This commit is contained in:
gabi
2014-10-18 18:35:48 +03:00
parent e6345e008b
commit 21065ec036
5 changed files with 41 additions and 21 deletions

View File

@@ -22,7 +22,6 @@ public:
stack_devicebuf() = default;
~stack_devicebuf() = default;
stack_devicebuf& operator=(const stack_devicebuf&) = delete;
stack_devicebuf(const stack_devicebuf& other) :std::basic_streambuf<char>(), _stackbuf(other._stackbuf)
{}
@@ -34,6 +33,12 @@ public:
other.clear();
}
stack_devicebuf& operator=(stack_devicebuf&& other)
{
std::swap(_stackbuf, other._stackbuf);
return *this;
}
const stackbuf_t& buf() const
{
return _stackbuf;
@@ -76,8 +81,7 @@ public:
fast_oss() :std::ostream(&_dev) {}
~fast_oss() = default;
fast_oss& operator=(const fast_oss& other) = delete;
fast_oss& operator=(const fast_oss&& other) = delete;
fast_oss(const fast_oss& other) :std::basic_ios<char>(), std::ostream(&_dev), _dev(other._dev)
{}
@@ -87,6 +91,21 @@ public:
other.clear();
}
fast_oss& operator=(fast_oss&& other)
{
swap(*this, other);
return *this;
}
void swap(fast_oss& first, fast_oss& second) // nothrow
{
using std::swap;
swap(first._dev, second._dev);
}
std::string str()
{
auto buffer = _dev.buf();
@@ -136,8 +155,8 @@ public:
auto buffer = oss.buf();
_dev.sputn(buffer.data(), buffer.size());
}
private:
stack_devicebuf _dev;
};