Added move assignment operator to DetachedBuffer.

Change-Id: I4610946ac27d9d0d73c2fc2e4834bd2cfed88cdc
Tested: on Linux.
This commit is contained in:
Wouter van Oortmerssen
2017-06-16 15:04:42 -07:00
parent 3c3742a54a
commit f52f848b95
2 changed files with 12 additions and 1 deletions

View File

@@ -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_);

View File

@@ -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());