diff --git a/AK/Noncopyable.h b/AK/Noncopyable.h index 0ccc62acde7..a2a7e775937 100644 --- a/AK/Noncopyable.h +++ b/AK/Noncopyable.h @@ -25,3 +25,46 @@ public: \ public: \ c(c const&) = default; \ c& operator=(c const&) = default + +#define AK_MAKE_CONDITIONALLY_NONMOVABLE(c, ...) \ +public: \ + c(c&&) \ + requires(!(AK::Detail::IsMoveConstructible __VA_ARGS__)) \ + = delete; \ + c& operator=(c&&) \ + requires(!(AK::Detail::IsMoveConstructible __VA_ARGS__) \ + || !(AK::Detail::IsDestructible __VA_ARGS__)) \ + = delete + +#define AK_MAKE_CONDITIONALLY_MOVABLE(c, T) \ + AK_MAKE_CONDITIONALLY_NONMOVABLE(c, T); \ + c(c&&) = default; \ + c& operator=(c&&) = default + +#define AK_MAKE_CONDITIONALLY_NONCOPYABLE(c, ...) \ +public: \ + c(c const&) \ + requires(!(AK::Detail::IsCopyConstructible __VA_ARGS__)) \ + = delete; \ + c& operator=(c const&) \ + requires(!(AK::Detail::IsCopyConstructible __VA_ARGS__) \ + || !(AK::Detail::IsDestructible __VA_ARGS__)) \ + = delete + +#define AK_MAKE_CONDITIONALLY_COPYABLE(c, ...) \ + AK_MAKE_CONDITIONALLY_NONCOPYABLE(c, __VA_ARGS__); \ + c(c const&) = default; \ + c& operator=(c const&) = default + +#define AK_MAKE_CONDITIONALLY_NONDESTRUCTIBLE(c, ...) \ +public: \ + ~c() \ + requires(!(AK::Detail::IsDestructible __VA_ARGS__)) \ + = delete + +#define AK_MAKE_CONDITIONALLY_DESTRUCTIBLE(c, ...) \ +public: \ + ~c() \ + requires(!(AK::Detail::IsDestructible __VA_ARGS__)) \ + = delete; \ + ~c() = default diff --git a/AK/Optional.h b/AK/Optional.h index 77bd8fe22cf..0e2c39b7f83 100644 --- a/AK/Optional.h +++ b/AK/Optional.h @@ -8,6 +8,7 @@ #pragma once #include +#include #include #include #include @@ -189,28 +190,9 @@ public: return *this; } - Optional(Optional const& other) - requires(!IsCopyConstructible) - = delete; - Optional(Optional const& other) = default; - - Optional(Optional&& other) - requires(!IsMoveConstructible) - = delete; - - Optional& operator=(Optional const&) - requires(!IsCopyConstructible || !IsDestructible) - = delete; - Optional& operator=(Optional const&) = default; - - Optional& operator=(Optional&& other) - requires(!IsMoveConstructible || !IsDestructible) - = delete; - - ~Optional() - requires(!IsDestructible) - = delete; - ~Optional() = default; + AK_MAKE_CONDITIONALLY_COPYABLE(Optional, ); + AK_MAKE_CONDITIONALLY_NONMOVABLE(Optional, ); + AK_MAKE_CONDITIONALLY_DESTRUCTIBLE(Optional, ); ALWAYS_INLINE Optional(Optional const& other) requires(!IsTriviallyCopyConstructible) diff --git a/AK/Variant.h b/AK/Variant.h index 885f89570ea..7ae5619ef63 100644 --- a/AK/Variant.h +++ b/AK/Variant.h @@ -8,6 +8,7 @@ #include #include +#include #include #include @@ -267,30 +268,9 @@ public: { } - Variant(Variant const&) - requires(!(IsCopyConstructible && ...)) - = delete; - Variant(Variant const&) = default; - - Variant(Variant&&) - requires(!(IsMoveConstructible && ...)) - = delete; - Variant(Variant&&) = default; - - ~Variant() - requires(!(IsDestructible && ...)) - = delete; - ~Variant() = default; - - Variant& operator=(Variant const&) - requires(!(IsCopyConstructible && ...) || !(IsDestructible && ...)) - = delete; - Variant& operator=(Variant const&) = default; - - Variant& operator=(Variant&&) - requires(!(IsMoveConstructible && ...) || !(IsDestructible && ...)) - = delete; - Variant& operator=(Variant&&) = default; + AK_MAKE_CONDITIONALLY_COPYABLE(Variant, &&...); + AK_MAKE_CONDITIONALLY_MOVABLE(Variant, &&...); + AK_MAKE_CONDITIONALLY_DESTRUCTIBLE(Variant, &&...); ALWAYS_INLINE Variant(Variant const& old) requires(!(IsTriviallyCopyConstructible && ...))