Buffer type has to be moveable, always
This commit is contained in:
@ -16,7 +16,8 @@
|
|||||||
namespace asl
|
namespace asl
|
||||||
{
|
{
|
||||||
|
|
||||||
template<is_object T, allocator Allocator = DefaultAllocator>
|
template<typename T, allocator Allocator = DefaultAllocator>
|
||||||
|
requires is_object<T> && moveable<T>
|
||||||
class buffer
|
class buffer
|
||||||
{
|
{
|
||||||
T* m_data{};
|
T* m_data{};
|
||||||
@ -244,7 +245,6 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
constexpr buffer(buffer&& other)
|
constexpr buffer(buffer&& other)
|
||||||
requires moveable<T>
|
|
||||||
: buffer(std::move(other.m_allocator))
|
: buffer(std::move(other.m_allocator))
|
||||||
{
|
{
|
||||||
move_from_other(std::move(other), false);
|
move_from_other(std::move(other), false);
|
||||||
@ -259,7 +259,6 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
constexpr buffer& operator=(buffer&& other)
|
constexpr buffer& operator=(buffer&& other)
|
||||||
requires moveable<T>
|
|
||||||
{
|
{
|
||||||
if (&other == this) { return *this; }
|
if (&other == this) { return *this; }
|
||||||
move_from_other(std::move(other), true);
|
move_from_other(std::move(other), true);
|
||||||
|
@ -159,13 +159,19 @@ struct MoveableType
|
|||||||
MoveableType(const MoveableType&) = delete;
|
MoveableType(const MoveableType&) = delete;
|
||||||
MoveableType(MoveableType&& other) : moved{other.moved + 1}, value{other.value} {}
|
MoveableType(MoveableType&& other) : moved{other.moved + 1}, value{other.value} {}
|
||||||
MoveableType& operator=(const MoveableType&) = delete;
|
MoveableType& operator=(const MoveableType&) = delete;
|
||||||
MoveableType& operator=(MoveableType&&) = delete;
|
MoveableType& operator=(MoveableType&& other)
|
||||||
|
{
|
||||||
|
if (this == &other) { return *this; }
|
||||||
|
moved = other.moved + 1;
|
||||||
|
value = other.value;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
~MoveableType() = default;
|
~MoveableType() = default;
|
||||||
};
|
};
|
||||||
static_assert(!asl::trivially_copy_constructible<MoveableType>);
|
static_assert(!asl::trivially_copy_constructible<MoveableType>);
|
||||||
static_assert(!asl::trivially_move_constructible<MoveableType>);
|
static_assert(!asl::trivially_move_constructible<MoveableType>);
|
||||||
static_assert(!asl::copyable<MoveableType>);
|
static_assert(!asl::copyable<MoveableType>);
|
||||||
static_assert(asl::move_constructible<MoveableType>);
|
static_assert(asl::moveable<MoveableType>);
|
||||||
|
|
||||||
// NOLINTNEXTLINE(*-complexity)
|
// NOLINTNEXTLINE(*-complexity)
|
||||||
ASL_TEST(push_move)
|
ASL_TEST(push_move)
|
||||||
@ -213,6 +219,30 @@ ASL_TEST(push_move)
|
|||||||
ASL_TEST_EXPECT(b[3].moved == 1);
|
ASL_TEST_EXPECT(b[3].moved == 1);
|
||||||
ASL_TEST_EXPECT(b[4].value == 4);
|
ASL_TEST_EXPECT(b[4].value == 4);
|
||||||
ASL_TEST_EXPECT(b[4].moved == 0);
|
ASL_TEST_EXPECT(b[4].moved == 0);
|
||||||
|
|
||||||
|
asl::buffer<MoveableType> b2 = std::move(b);
|
||||||
|
ASL_TEST_EXPECT(b2[0].value == 0);
|
||||||
|
ASL_TEST_EXPECT(b2[0].moved == 2);
|
||||||
|
ASL_TEST_EXPECT(b2[1].value == 1);
|
||||||
|
ASL_TEST_EXPECT(b2[1].moved == 2);
|
||||||
|
ASL_TEST_EXPECT(b2[2].value == 2);
|
||||||
|
ASL_TEST_EXPECT(b2[2].moved == 1);
|
||||||
|
ASL_TEST_EXPECT(b2[3].value == 3);
|
||||||
|
ASL_TEST_EXPECT(b2[3].moved == 1);
|
||||||
|
ASL_TEST_EXPECT(b2[4].value == 4);
|
||||||
|
ASL_TEST_EXPECT(b2[4].moved == 0);
|
||||||
|
|
||||||
|
b = std::move(b2);
|
||||||
|
ASL_TEST_EXPECT(b[0].value == 0);
|
||||||
|
ASL_TEST_EXPECT(b[0].moved == 2);
|
||||||
|
ASL_TEST_EXPECT(b[1].value == 1);
|
||||||
|
ASL_TEST_EXPECT(b[1].moved == 2);
|
||||||
|
ASL_TEST_EXPECT(b[2].value == 2);
|
||||||
|
ASL_TEST_EXPECT(b[2].moved == 1);
|
||||||
|
ASL_TEST_EXPECT(b[3].value == 3);
|
||||||
|
ASL_TEST_EXPECT(b[3].moved == 1);
|
||||||
|
ASL_TEST_EXPECT(b[4].value == 4);
|
||||||
|
ASL_TEST_EXPECT(b[4].moved == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
ASL_TEST(clear)
|
ASL_TEST(clear)
|
||||||
|
Reference in New Issue
Block a user