From a141c401f78467bc15f62882fca5d55a007cacbb Mon Sep 17 00:00:00 2001 From: Steven Le Rouzic Date: Mon, 17 Feb 2025 00:21:48 +0100 Subject: Reorganize everything --- asl/tests/types.hpp | 89 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 asl/tests/types.hpp (limited to 'asl/tests/types.hpp') diff --git a/asl/tests/types.hpp b/asl/tests/types.hpp new file mode 100644 index 0000000..e65aa11 --- /dev/null +++ b/asl/tests/types.hpp @@ -0,0 +1,89 @@ +#pragma once + +#include "asl/base/utility.hpp" + +struct TrivialType +{ + int x; + TrivialType() = default; + TrivialType(const TrivialType&) = default; + TrivialType(TrivialType&&) = default; + TrivialType& operator=(const TrivialType&) = default; + TrivialType& operator=(TrivialType&&) = default; + ~TrivialType() = default; +}; + +struct TrivialTypeDefaultValue +{ + int x{}; + TrivialTypeDefaultValue() = default; + TrivialTypeDefaultValue(const TrivialTypeDefaultValue&) = default; + TrivialTypeDefaultValue(TrivialTypeDefaultValue&&) = default; + TrivialTypeDefaultValue& operator=(const TrivialTypeDefaultValue&) = default; + TrivialTypeDefaultValue& operator=(TrivialTypeDefaultValue&&) = default; + ~TrivialTypeDefaultValue() = default; +}; + +struct WithDestructor +{ + WithDestructor() = default; + WithDestructor(const WithDestructor&) = default; + WithDestructor(WithDestructor&&) = default; + WithDestructor& operator=(const WithDestructor&) = default; + WithDestructor& operator=(WithDestructor&&) = default; + ~WithDestructor() {} // NOLINT +}; + +struct Copyable // NOLINT +{ + Copyable(const Copyable&) {} // NOLINT + Copyable& operator=(const Copyable&); // NOLINT +}; + +struct MoveableOnly // NOLINT +{ + MoveableOnly(const MoveableOnly&) = delete; + MoveableOnly& operator=(const MoveableOnly&) = delete; + MoveableOnly(MoveableOnly&&); + MoveableOnly& operator=(MoveableOnly&&); // NOLINT +}; + +struct Pinned // NOLINT +{ + Pinned(const Pinned&) = delete; + Pinned& operator=(const Pinned&) = delete; + Pinned(Pinned&&) = delete; + Pinned& operator=(Pinned&&) = delete; +}; + +struct DestructorObserver +{ + bool* destroyed; + + explicit DestructorObserver(bool* destroyed_) : destroyed{destroyed_} {} + + DestructorObserver(const DestructorObserver&) = delete; + DestructorObserver& operator=(const DestructorObserver&) = delete; + + DestructorObserver(DestructorObserver&& other) + : destroyed{asl::exchange(other.destroyed, nullptr)} + {} + + DestructorObserver& operator=(DestructorObserver&& other) + { + if (this != &other) + { + destroyed = asl::exchange(other.destroyed, nullptr); + } + return *this; + } + + ~DestructorObserver() + { + if (destroyed != nullptr) + { + ASL_ASSERT_RELEASE(*destroyed == false); + *destroyed = true; + } + } +}; -- cgit