Disabled the move semantics from Buffer, just in case.

Disabled the move semantics test
This commit is contained in:
Paul Ferrand 2019-12-02 12:22:02 +01:00
parent 5d8e758724
commit 056337b5f0
2 changed files with 32 additions and 30 deletions

View file

@ -147,18 +147,19 @@ public:
* *
* @param other * @param other
*/ */
Buffer(Buffer<Type>&& other) Buffer(Buffer<Type>&& other) = delete;
{ // {
if (this != &other) { // if (this != &other) {
std::free(paddedData); // counter().bufferDeleted(largerSize * sizeof(value_type));
largerSize = std::exchange(other.largerSize, 0); // std::free(paddedData);
alignedSize = std::exchange(other.alignedSize, 0); // largerSize = std::exchange(other.largerSize, 0);
paddedData = std::exchange(other.paddedData, nullptr); // alignedSize = std::exchange(other.alignedSize, 0);
normalData = std::exchange(other.normalData, nullptr); // paddedData = std::exchange(other.paddedData, nullptr);
normalEnd = std::exchange(other.normalEnd, nullptr); // normalData = std::exchange(other.normalData, nullptr);
_alignedEnd = std::exchange(other._alignedEnd, nullptr); // normalEnd = std::exchange(other.normalEnd, nullptr);
} // _alignedEnd = std::exchange(other._alignedEnd, nullptr);
} // }
// }
Buffer<Type>& operator=(const Buffer<Type>& other) Buffer<Type>& operator=(const Buffer<Type>& other)
{ {
@ -169,19 +170,20 @@ public:
return *this; return *this;
} }
Buffer<Type>& operator=(Buffer<Type>&& other) Buffer<Type>& operator=(Buffer<Type>&& other) = delete;
{ // {
if (this != &other) { // if (this != &other) {
std::free(paddedData); // counter().bufferDeleted(largerSize * sizeof(value_type));
largerSize = std::exchange(other.largerSize, 0); // std::free(paddedData);
alignedSize = std::exchange(other.alignedSize, 0); // largerSize = std::exchange(other.largerSize, 0);
paddedData = std::exchange(other.paddedData, nullptr); // alignedSize = std::exchange(other.alignedSize, 0);
normalData = std::exchange(other.normalData, nullptr); // paddedData = std::exchange(other.paddedData, nullptr);
normalEnd = std::exchange(other.normalEnd, nullptr); // normalData = std::exchange(other.normalData, nullptr);
_alignedEnd = std::exchange(other._alignedEnd, nullptr); // normalEnd = std::exchange(other.normalEnd, nullptr);
} // _alignedEnd = std::exchange(other._alignedEnd, nullptr);
return *this; // }
} // return *this;
// }
Type& operator[](int idx) { return *(normalData + idx); } Type& operator[](int idx) { return *(normalData + idx); }
constexpr pointer data() const noexcept { return normalData; } constexpr pointer data() const noexcept { return normalData; }

View file

@ -157,8 +157,8 @@ TEST_CASE("[Buffer] Copy and move")
checkBoundaries(copyConstructed, baseSize); checkBoundaries(copyConstructed, baseSize);
REQUIRE(std::all_of(copyConstructed.begin(), copyConstructed.end(), [](auto value) { return value == 1.0f; })); REQUIRE(std::all_of(copyConstructed.begin(), copyConstructed.end(), [](auto value) { return value == 1.0f; }));
sfz::Buffer<float> moveConstructed { std::move(buffer) }; // sfz::Buffer<float> moveConstructed { std::move(buffer) };
REQUIRE(buffer.empty()); // REQUIRE(buffer.empty());
checkBoundaries(moveConstructed, baseSize); // checkBoundaries(moveConstructed, baseSize);
REQUIRE(std::all_of(moveConstructed.begin(), moveConstructed.end(), [](auto value) { return value == 1.0f; })); // REQUIRE(std::all_of(moveConstructed.begin(), moveConstructed.end(), [](auto value) { return value == 1.0f; }));
} }