Skip to content

Commit e358b0a

Browse files
committed
buf
1 parent 7bd9c58 commit e358b0a

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

src/Buffer/Buffer.hpp

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -264,11 +264,28 @@ class Buffer {
264264

265265
/** =============== Buffer definition =============== */
266266
/** Copy of any kind is disabled. Move is allowed. */
267-
Buffer(const allocator& all = allocator());
267+
Buffer(allocator&& all = allocator());
268268
Buffer(const Buffer& buf) = delete;
269269
Buffer& operator = (const Buffer& buf) = delete;
270-
Buffer(Buffer &&buf) noexcept = default;
271-
Buffer &operator=(Buffer &&buf) noexcept = default;
270+
Buffer(Buffer &&other) noexcept
271+
{
272+
/* Call move assignment operator. */
273+
*this = std::forward<Buffer>(other);
274+
}
275+
Buffer &operator=(Buffer &&other)
276+
{
277+
if (this == &other)
278+
return *this;
279+
m_blocks = std::move(other.m_blocks);
280+
assert(other.m_blocks.isEmpty());
281+
m_iterators = std::move(other.m_iterators);
282+
m_begin = other.m_begin;
283+
other.m_begin = nullptr;
284+
m_end = other.m_end;
285+
other.m_end = nullptr;
286+
m_all = std::move(other.m_all);
287+
return *this;
288+
}
272289
~Buffer() noexcept;
273290

274291
/**
@@ -647,7 +664,7 @@ Buffer<N, allocator>::iterator_common<LIGHT>::moveBackward(size_t step)
647664
}
648665

649666
template <size_t N, class allocator>
650-
Buffer<N, allocator>::Buffer(const allocator &all) : m_all(all)
667+
Buffer<N, allocator>::Buffer(allocator &&all) : m_all(std::forward<allocator>(all))
651668
{
652669
static_assert((N & (N - 1)) == 0, "N must be power of 2");
653670
static_assert(allocator::REAL_SIZE % alignof(Block) == 0,

0 commit comments

Comments
 (0)