mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-28 02:48:05 +00:00
Added move assignment operator to DetachedBuffer.
Change-Id: I4610946ac27d9d0d73c2fc2e4834bd2cfed88cdc Tested: on Linux.
This commit is contained in:
@@ -453,6 +453,16 @@ class DetachedBuffer {
|
|||||||
other.size_ = 0;
|
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() {
|
~DetachedBuffer() {
|
||||||
if (buf_) {
|
if (buf_) {
|
||||||
assert(allocator_);
|
assert(allocator_);
|
||||||
|
|||||||
@@ -1640,7 +1640,8 @@ int main(int /*argc*/, const char * /*argv*/[]) {
|
|||||||
// Run our various test suites:
|
// Run our various test suites:
|
||||||
|
|
||||||
std::string rawbuf;
|
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()),
|
AccessFlatBufferTest(reinterpret_cast<const uint8_t *>(rawbuf.c_str()),
|
||||||
rawbuf.length());
|
rawbuf.length());
|
||||||
AccessFlatBufferTest(flatbuf.data(), flatbuf.size());
|
AccessFlatBufferTest(flatbuf.data(), flatbuf.size());
|
||||||
|
|||||||
Reference in New Issue
Block a user