Added move assignment operator to DetachedBuffer.

Change-Id: I4610946ac27d9d0d73c2fc2e4834bd2cfed88cdc
Tested: on Linux.
parent 3c3742a5
......@@ -453,6 +453,16 @@ class DetachedBuffer {
other.size_ = 0;
}
DetachedBuffer &operator=(DetachedBuffer &&other) {
std::swap(allocator_, other.allocator_);
std::swap(own_allocator_, other.own_allocator_);
std::swap(buf_, other.buf_);
std::swap(reserved_, other.reserved_);
std::swap(cur_, other.cur_);
std::swap(size_, other.size_);
return *this;
}
~DetachedBuffer() {
if (buf_) {
assert(allocator_);
......
......@@ -1640,7 +1640,8 @@ int main(int /*argc*/, const char * /*argv*/[]) {
// Run our various test suites:
std::string rawbuf;
auto flatbuf = CreateFlatBufferTest(rawbuf);
auto flatbuf1 = CreateFlatBufferTest(rawbuf);
auto flatbuf = std::move(flatbuf1); // Test move assignment.
AccessFlatBufferTest(reinterpret_cast<const uint8_t *>(rawbuf.c_str()),
rawbuf.length());
AccessFlatBufferTest(flatbuf.data(), flatbuf.size());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment