Allow move assignment for Data class
This commit is contained in:
parent
40451e762c
commit
dcc979d65f
@ -24,6 +24,17 @@ Data::Data(Data &&rhs)
|
|||||||
: _size(rhs._size), _data(rhs._data) {
|
: _size(rhs._size), _data(rhs._data) {
|
||||||
// Make rhs invalid, so the memory doesn't get freed in its destructor.
|
// Make rhs invalid, so the memory doesn't get freed in its destructor.
|
||||||
rhs._data = nullptr;
|
rhs._data = nullptr;
|
||||||
|
rhs._size = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
Data &Data::operator=(Data &&rhs) {
|
||||||
|
std::free(_data);
|
||||||
|
_data = rhs._data;
|
||||||
|
_size = rhs._size;
|
||||||
|
rhs._data = nullptr;
|
||||||
|
rhs._size = 0;
|
||||||
|
|
||||||
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
Data::~Data() {
|
Data::~Data() {
|
||||||
|
@ -13,9 +13,12 @@ namespace cpputils {
|
|||||||
class Data {
|
class Data {
|
||||||
public:
|
public:
|
||||||
explicit Data(size_t size);
|
explicit Data(size_t size);
|
||||||
Data(Data &&rhs); // move constructor
|
|
||||||
virtual ~Data();
|
virtual ~Data();
|
||||||
|
|
||||||
|
Data(Data &&rhs); // move constructor
|
||||||
|
//TODO Test move assignment (and if not tested yet, also move constructor)
|
||||||
|
Data &operator=(Data &&rhs); // move assignment
|
||||||
|
|
||||||
Data copy() const;
|
Data copy() const;
|
||||||
|
|
||||||
void *data();
|
void *data();
|
||||||
|
Loading…
Reference in New Issue
Block a user