mbv: move a few things around
This commit is contained in:
30
mbv/lib/buffer.h
Normal file
30
mbv/lib/buffer.h
Normal file
@@ -0,0 +1,30 @@
|
||||
#pragma once
|
||||
|
||||
#include <span>
|
||||
#include <utility>
|
||||
|
||||
struct buffer {
|
||||
std::span<std::byte> data;
|
||||
|
||||
buffer() = default;
|
||||
buffer(std::span<std::byte> d) : data(d) {}
|
||||
|
||||
static buffer make(size_t size) {
|
||||
return buffer({new std::byte[size], size});
|
||||
}
|
||||
|
||||
buffer(buffer& other) = delete;
|
||||
buffer& operator=(buffer& other) = delete;
|
||||
|
||||
buffer(buffer&& other) : data(std::exchange(other.data, {})) {}
|
||||
buffer& operator=(buffer&& other) {
|
||||
data = std::exchange(other.data, {});
|
||||
return *this;
|
||||
}
|
||||
|
||||
~buffer() {
|
||||
if (data.data()) {
|
||||
delete[] data.data();
|
||||
};
|
||||
}
|
||||
};
|
Reference in New Issue
Block a user