Skip to content
Snippets Groups Projects
Commit e14d78c6 authored by 数学の武士's avatar 数学の武士
Browse files

.

parent 22a45a4b
No related branches found
No related tags found
No related merge requests found
......@@ -15,6 +15,7 @@ public:
buffer(const size_t required_size, const MemType mem); // Done
buffer(const buffer& other); // Done
buffer(buffer&& other) noexcept; // Done
void swap(buffer& other) noexcept;
~buffer(); // Done
bool is_available() const; // Done
......
......@@ -55,7 +55,7 @@ buffer::buffer(const buffer& other)
}
buffer::buffer(buffer&& other) noexcept :
mem(other.mem), ptr(std::move(other.ptr)), allocated_size(other.allocated_size),
mem(other.mem), ptr(other.ptr), allocated_size(other.allocated_size),
scalar_size(other.scalar_size), is_free(other.is_free),
id(other.id)
{
......@@ -84,6 +84,23 @@ buffer& buffer::operator=(const buffer& other)
return *this;
}
void buffer::swap(buffer& other) noexcept
{
std::swap(ptr, other.ptr);
mem = other.mem;
allocated_size = other.allocated_size;
scalar_size = other.scalar_size;
is_free = other.is_free;
id = other.id;
other.ptr = nullptr;
other.allocated_size = 0;
other.scalar_size = 0;
other.is_free = false;
other.id = -1;
other.mem = MemType::UNDEF;
}
buffer& buffer::operator=(buffer&& other) noexcept
{
if (this != &other)
......@@ -91,19 +108,8 @@ buffer& buffer::operator=(buffer&& other) noexcept
assert(other.mem != MemType::UNDEF);
deallocate();
mem = other.mem;
ptr = std::move(other.ptr);
allocated_size = other.allocated_size;
scalar_size = other.scalar_size;
is_free = other.is_free;
id = other.id;
other.ptr = nullptr;
other.allocated_size = 0;
other.scalar_size = 0;
other.is_free = false;
other.id = -1;
other.mem = MemType::UNDEF;
buffer temp{std::move(other)};
swap(temp);
}
return *this;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment