AK: Add IsTriviallyRelocatable type trait

This commit is contained in:
Tim Ledbetter 2026-02-06 00:31:51 +00:00 committed by Jelle Raaijmakers
parent c173a66754
commit 8dd3c20436
2 changed files with 30 additions and 0 deletions

View file

@ -551,6 +551,9 @@ inline constexpr bool IsMoveAssignable = IsAssignable<AddLvalueReference<T>, Add
template<typename T> template<typename T>
inline constexpr bool IsTriviallyMoveAssignable = IsTriviallyAssignable<AddLvalueReference<T>, AddRvalueReference<T>>; inline constexpr bool IsTriviallyMoveAssignable = IsTriviallyAssignable<AddLvalueReference<T>, AddRvalueReference<T>>;
template<typename T>
inline constexpr bool IsTriviallyRelocatable = IsTriviallyMoveConstructible<T> && IsTriviallyDestructible<T>;
template<typename T, template<typename...> typename U> template<typename T, template<typename...> typename U>
inline constexpr bool IsSpecializationOf = false; inline constexpr bool IsSpecializationOf = false;
@ -716,6 +719,7 @@ using AK::Detail::IsTriviallyCopyConstructible;
using AK::Detail::IsTriviallyDestructible; using AK::Detail::IsTriviallyDestructible;
using AK::Detail::IsTriviallyMoveAssignable; using AK::Detail::IsTriviallyMoveAssignable;
using AK::Detail::IsTriviallyMoveConstructible; using AK::Detail::IsTriviallyMoveConstructible;
using AK::Detail::IsTriviallyRelocatable;
using AK::Detail::IsUnion; using AK::Detail::IsUnion;
using AK::Detail::IsUnsigned; using AK::Detail::IsUnsigned;
using AK::Detail::IsVoid; using AK::Detail::IsVoid;

View file

@ -243,6 +243,32 @@ TEST_CASE(IsDestructible)
EXPECT_TRAIT_FALSE(IsTriviallyDestructible, C); EXPECT_TRAIT_FALSE(IsTriviallyDestructible, C);
} }
TEST_CASE(IsTriviallyRelocatable)
{
EXPECT_TRAIT_TRUE(IsTriviallyRelocatable, int, float, char, Empty);
EXPECT_TRAIT_TRUE(IsTriviallyRelocatable, int*, Empty*);
struct TriviallyRelocatable {
};
EXPECT_TRAIT_TRUE(IsTriviallyRelocatable, TriviallyRelocatable);
struct NonTriviallyRelocatable {
NonTriviallyRelocatable(NonTriviallyRelocatable&&) { }
~NonTriviallyRelocatable() { }
};
EXPECT_TRAIT_FALSE(IsTriviallyRelocatable, NonTriviallyRelocatable);
struct NonTrivialMove {
NonTrivialMove(NonTrivialMove&&) { }
};
EXPECT_TRAIT_FALSE(IsTriviallyRelocatable, NonTrivialMove);
struct NonTrivialDestructor {
~NonTrivialDestructor() { }
};
EXPECT_TRAIT_FALSE(IsTriviallyRelocatable, NonTrivialDestructor);
}
TEST_CASE(CommonType) TEST_CASE(CommonType)
{ {
using TCommon0 = CommonType<int, float, char>; using TCommon0 = CommonType<int, float, char>;