- data_deleter() : type_(Free) {}
- data_deleter(Type type, std::size_t size) : type_(type), size_(size) {}
- void operator()(void* p) const;
-};
+ buffer() {}
+ buffer(std::size_t size, Type type = Type::Malloc);
+ buffer(void* data, std::size_t size, Type type = Type::Malloc) :
+ data_(data), size_(size), type_(type) {}
+ void clear() noexcept;
+ ~buffer() noexcept { clear(); }
+
+ // No copy
+ buffer(buffer const& buffer) = delete;
+ buffer& operator=(buffer const& buffer) = delete;
+
+ // Move
+ buffer(buffer&& that) noexcept
+ : data_(that.data_), size_(that.size_), type_(that.type_)
+ {
+ that.data_ = nullptr;
+ that.size_ = 0;
+ that.type_ = Type::Malloc;
+ }
+ buffer& operator=(buffer&& that) noexcept
+ {
+ clear();
+ data_ = that.data_;
+ size_ = that.size_;
+ type_ = that.type_;
+ that.data_ = nullptr;
+ that.size_ = 0;
+ that.type_ = Type::Malloc;
+ return *this;
+ }