diff --git a/Redcraft.Utility/Source/Public/Templates/Any.h b/Redcraft.Utility/Source/Public/Templates/Any.h index f5a68d0..c242c71 100644 --- a/Redcraft.Utility/Source/Public/Templates/Any.h +++ b/Redcraft.Utility/Source/Public/Templates/Any.h @@ -21,6 +21,13 @@ NAMESPACE_MODULE_BEGIN(Utility) // 3) it is less exception-safe // But we don't follow the the copy-and-swap idiom, because we assume that no function throws an exception. +NAMESPACE_PRIVATE_BEGIN + +template +concept CFAnyPlaceable = CDestructible> && CCopyConstructible> && CMoveConstructible> && CSwappable>; + +NAMESPACE_PRIVATE_END + class alignas(16) FAny { public: @@ -79,15 +86,14 @@ public: } } - template requires (CDestructible> - && CConstructibleFrom, Ts&&...>) + template requires (NAMESPACE_PRIVATE::CFAnyPlaceable && CConstructibleFrom, Ts&&...>) FORCEINLINE explicit FAny(TInPlaceType, Ts&&... Args) { EmplaceImpl(Forward(Args)...); } template requires (!CBaseOf> && !CTInPlaceType> - && CDestructible> && CConstructibleFrom, T&&>) + && NAMESPACE_PRIVATE::CFAnyPlaceable && CConstructibleFrom, T&&>) FORCEINLINE FAny(T&& InValue) : FAny(InPlaceType>, Forward(InValue)) { } @@ -213,7 +219,7 @@ public: } template requires (!CBaseOf> && !CTInPlaceType> - && CDestructible>&& CConstructibleFrom, T&&>) + && NAMESPACE_PRIVATE::CFAnyPlaceable && CConstructibleFrom, T&&>) FORCEINLINE FAny& operator=(T&& InValue) { using DecayedType = TDecay; @@ -231,8 +237,7 @@ public: return *this; } - template requires (CDestructible> - && CConstructibleFrom, Ts&&...>) + template requires (NAMESPACE_PRIVATE::CFAnyPlaceable && CConstructibleFrom, Ts&&...>) FORCEINLINE TDecay& Emplace(Ts&&... Args) { Destroy(); @@ -247,22 +252,22 @@ public: template FORCEINLINE constexpr bool HoldsAlternative() const { return IsValid() ? GetTypeInfo() == typeid(T) : false; } - template requires (CSameAs>&& CDestructible>) + template requires (CSameAs> && NAMESPACE_PRIVATE::CFAnyPlaceable) FORCEINLINE constexpr T& GetValue() & { checkf(HoldsAlternative(), TEXT("It is an error to call GetValue() on an wrong TAny. Please either check HoldsAlternative() or use Get(DefaultValue) instead.")); return *reinterpret_cast< T*>(GetStorage()); } - - template requires (CSameAs>&& CDestructible>) + + template requires (CSameAs> && NAMESPACE_PRIVATE::CFAnyPlaceable) FORCEINLINE constexpr T&& GetValue() && { checkf(HoldsAlternative(), TEXT("It is an error to call GetValue() on an wrong TAny. Please either check HoldsAlternative() or use Get(DefaultValue) instead.")); return MoveTemp(*reinterpret_cast< T*>(GetStorage())); } - - template requires (CSameAs>&& CDestructible>) + + template requires (CSameAs> && NAMESPACE_PRIVATE::CFAnyPlaceable) FORCEINLINE constexpr const T& GetValue() const& { checkf(HoldsAlternative(), TEXT("It is an error to call GetValue() on an wrong TAny. Please either check HoldsAlternative() or use Get(DefaultValue) instead.")); return *reinterpret_cast(GetStorage()); } - - template requires (CSameAs>&& CDestructible>) + + template requires (CSameAs> && NAMESPACE_PRIVATE::CFAnyPlaceable) FORCEINLINE constexpr const T&& GetValue() const&& { checkf(HoldsAlternative(), TEXT("It is an error to call GetValue() on an wrong TAny. Please either check HoldsAlternative() or use Get(DefaultValue) instead.")); return MoveTemp(*reinterpret_cast(GetStorage())); } - - template requires (CSameAs> && CDestructible>) + + template requires (CSameAs> && NAMESPACE_PRIVATE::CFAnyPlaceable) FORCEINLINE constexpr T& Get( T& DefaultValue) & { return HoldsAlternative() ? GetValue() : DefaultValue; } - template requires (CSameAs> && CDestructible>) + template requires (CSameAs> && NAMESPACE_PRIVATE::CFAnyPlaceable) FORCEINLINE constexpr const T& Get(const T& DefaultValue) const& { return HoldsAlternative() ? GetValue() : DefaultValue; } FORCEINLINE void Reset() diff --git a/Redcraft.Utility/Source/Public/Templates/Atomic.h b/Redcraft.Utility/Source/Public/Templates/Atomic.h index 00d6bb9..5f53d3e 100644 --- a/Redcraft.Utility/Source/Public/Templates/Atomic.h +++ b/Redcraft.Utility/Source/Public/Templates/Atomic.h @@ -229,10 +229,12 @@ protected: NAMESPACE_PRIVATE_END -template +template requires (CTriviallyCopyable + && CCopyConstructible && CMoveConstructible + && CCopyAssignable && CMoveAssignable) struct TAtomic : STRONG_INHERIT(NAMESPACE_PRIVATE::TAtomicImpl); -template +template requires (CTriviallyCopyable) struct TAtomicRef : STRONG_INHERIT(NAMESPACE_PRIVATE::TAtomicImpl); template diff --git a/Redcraft.Utility/Source/Public/Templates/Optional.h b/Redcraft.Utility/Source/Public/Templates/Optional.h index 82adf09..b448b44 100644 --- a/Redcraft.Utility/Source/Public/Templates/Optional.h +++ b/Redcraft.Utility/Source/Public/Templates/Optional.h @@ -11,27 +11,31 @@ NAMESPACE_REDCRAFT_BEGIN NAMESPACE_MODULE_BEGIN(Redcraft) NAMESPACE_MODULE_BEGIN(Utility) +template requires (CDestructible) +class TOptional; + +NAMESPACE_PRIVATE_BEGIN + +template +concept CTOptionalAllowUnwrappable = + !(CConstructibleFrom& > + || CConstructibleFrom& > + || CConstructibleFrom&&> + || CConstructibleFrom&&> + || CConvertibleTo< TOptional&, U> + || CConvertibleTo&, U> + || CConvertibleTo< TOptional&&, U> + || CConvertibleTo&&, U> + || CAssignableFrom& > + || CAssignableFrom& > + || CAssignableFrom&&> + || CAssignableFrom&&>); + +NAMESPACE_PRIVATE_END + template requires (CDestructible) class TOptional { -private: - - template - struct TAllowUnwrapping : TBoolConstant& > - || CConstructibleFrom& > - || CConstructibleFrom&&> - || CConstructibleFrom&&> - || CConvertibleTo< TOptional&, OptionalType> - || CConvertibleTo&, OptionalType> - || CConvertibleTo< TOptional&&, OptionalType> - || CConvertibleTo&&, OptionalType> - || CAssignableFrom& > - || CAssignableFrom& > - || CAssignableFrom&&> - || CAssignableFrom&&> - )> { }; - public: using ValueType = OptionalType; @@ -69,14 +73,14 @@ public: if (InValue.IsValid()) new (&Value) OptionalType(MoveTemp(InValue.GetValue())); } - template requires (CConstructibleFrom && TAllowUnwrapping::Value) + template requires (CConstructibleFrom && NAMESPACE_PRIVATE::CTOptionalAllowUnwrappable) FORCEINLINE constexpr explicit (!CConvertibleTo) TOptional(const TOptional& InValue) : bIsValid(InValue.IsValid()) { if (InValue.IsValid()) new (&Value) OptionalType(InValue.GetValue()); } - template requires (CConstructibleFrom && TAllowUnwrapping::Value) + template requires (CConstructibleFrom && NAMESPACE_PRIVATE::CTOptionalAllowUnwrappable) FORCEINLINE constexpr explicit (!CConvertibleTo) TOptional(TOptional&& InValue) : bIsValid(InValue.IsValid()) { @@ -137,7 +141,7 @@ public: } template requires (CConstructibleFrom - && CAssignableFrom && TAllowUnwrapping::Value) + && CAssignableFrom && NAMESPACE_PRIVATE::CTOptionalAllowUnwrappable) FORCEINLINE constexpr TOptional& operator=(const TOptional& InValue) { if (!InValue.IsValid()) @@ -157,7 +161,7 @@ public: } template requires (CConstructibleFrom - && CAssignableFrom && TAllowUnwrapping::Value) + && CAssignableFrom && NAMESPACE_PRIVATE::CTOptionalAllowUnwrappable) FORCEINLINE constexpr TOptional& operator=(TOptional&& InValue) { if (!InValue.IsValid()) diff --git a/Redcraft.Utility/Source/Public/Templates/ReferenceWrapper.h b/Redcraft.Utility/Source/Public/Templates/ReferenceWrapper.h index 70f8114..619b564 100644 --- a/Redcraft.Utility/Source/Public/Templates/ReferenceWrapper.h +++ b/Redcraft.Utility/Source/Public/Templates/ReferenceWrapper.h @@ -122,6 +122,25 @@ using TUnwrapReference = typename NAMESPACE_PRIVATE::TUnwrapReferenceImpl::Ty template using TUnwrapRefDecay = typename NAMESPACE_PRIVATE::TUnwrapRefDecayImpl::Type; +NAMESPACE_PRIVATE_BEGIN + +template +concept CTOptionalRefAllowUnwrappable = + !(CConstructibleFrom& > + || CConstructibleFrom& > + || CConstructibleFrom&&> + || CConstructibleFrom&&> + || CConvertibleTo< TOptional&, U> + || CConvertibleTo&, U> + || CConvertibleTo< TOptional&&, U> + || CConvertibleTo&&, U> + || CAssignableFrom& > + || CAssignableFrom& > + || CAssignableFrom&&> + || CAssignableFrom&&>); + +NAMESPACE_PRIVATE_END + template class TOptional> { @@ -129,22 +148,6 @@ private: using OptionalType = TReferenceWrapper; - template - struct TAllowUnwrapping : TBoolConstant < !( - CConstructibleFrom& > - || CConstructibleFrom& > - || CConstructibleFrom&&> - || CConstructibleFrom&&> - || CConvertibleTo< TOptional&, OptionalType> - || CConvertibleTo&, OptionalType> - || CConvertibleTo< TOptional&&, OptionalType> - || CConvertibleTo&&, OptionalType> - || CAssignableFrom& > - || CAssignableFrom& > - || CAssignableFrom&&> - || CAssignableFrom&&> - )> { }; - public: using ValueType = OptionalType; @@ -167,7 +170,7 @@ public: FORCEINLINE TOptional(const TOptional& InValue) = default; FORCEINLINE TOptional(TOptional&& InValue) = default; - template requires (CConstructibleFrom && TAllowUnwrapping::Value) + template requires (CConstructibleFrom && NAMESPACE_PRIVATE::CTOptionalRefAllowUnwrappable) FORCEINLINE constexpr explicit (!CConvertibleTo) TOptional(const TOptional& InValue) : Reference(InValue.Reference) { } @@ -178,7 +181,7 @@ public: FORCEINLINE TOptional& operator=(TOptional&& InValue) = default; template requires (CConstructibleFrom - && CAssignableFrom && TAllowUnwrapping::Value) + && CAssignableFrom && NAMESPACE_PRIVATE::CTOptionalRefAllowUnwrappable) FORCEINLINE constexpr TOptional& operator=(const TOptional& InValue) { Reference = InValue.Reference;