feat(typetraits): add TypeTraits/CopyQualifiers.h and the corresponding testing

This commit is contained in:
_Redstone_c_ 2022-03-15 14:25:06 +08:00
parent f7b611febc
commit 8188d29a58
3 changed files with 115 additions and 0 deletions

View File

@ -450,6 +450,84 @@ void TestTypeTraits()
always_check((TIsSwappableWith<int32&, int32&>::Value)); always_check((TIsSwappableWith<int32&, int32&>::Value));
// CopyQualifiers.h
always_check((TIsSame< int32, TCopyConst< int32, int32>::Type>::Value));
always_check((TIsSame<const int32, TCopyConst<const int32, int32>::Type>::Value));
always_check((TIsSame<const int32, TCopyConst<const volatile int32, int32>::Type>::Value));
always_check((TIsSame<const int32, TCopyConst< int32, const int32>::Type>::Value));
always_check((TIsSame<const int32, TCopyConst<const int32, const int32>::Type>::Value));
always_check((TIsSame<const int32, TCopyConst<const volatile int32, const int32>::Type>::Value));
always_check((TIsSame<const volatile int32, TCopyConst< int32, const volatile int32>::Type>::Value));
always_check((TIsSame<const volatile int32, TCopyConst<const int32, const volatile int32>::Type>::Value));
always_check((TIsSame<const volatile int32, TCopyConst<const volatile int32, const volatile int32>::Type>::Value));
always_check((TIsSame< int32, TCopyVolatile< int32, int32>::Type>::Value));
always_check((TIsSame< int32, TCopyVolatile<const int32, int32>::Type>::Value));
always_check((TIsSame< volatile int32, TCopyVolatile<const volatile int32, int32>::Type>::Value));
always_check((TIsSame<const int32, TCopyVolatile< int32, const int32>::Type>::Value));
always_check((TIsSame<const int32, TCopyVolatile<const int32, const int32>::Type>::Value));
always_check((TIsSame<const volatile int32, TCopyVolatile<const volatile int32, const int32>::Type>::Value));
always_check((TIsSame<const volatile int32, TCopyVolatile< int32, const volatile int32>::Type>::Value));
always_check((TIsSame<const volatile int32, TCopyVolatile<const int32, const volatile int32>::Type>::Value));
always_check((TIsSame<const volatile int32, TCopyVolatile<const volatile int32, const volatile int32>::Type>::Value));
always_check((TIsSame< int32, TCopyCV< int32, int32>::Type>::Value));
always_check((TIsSame<const int32, TCopyCV<const int32, int32>::Type>::Value));
always_check((TIsSame<const volatile int32, TCopyCV<const volatile int32, int32>::Type>::Value));
always_check((TIsSame<const int32, TCopyCV< int32, const int32>::Type>::Value));
always_check((TIsSame<const int32, TCopyCV<const int32, const int32>::Type>::Value));
always_check((TIsSame<const volatile int32, TCopyCV<const volatile int32, const int32>::Type>::Value));
always_check((TIsSame<const volatile int32, TCopyCV< int32, const volatile int32>::Type>::Value));
always_check((TIsSame<const volatile int32, TCopyCV<const int32, const volatile int32>::Type>::Value));
always_check((TIsSame<const volatile int32, TCopyCV<const volatile int32, const volatile int32>::Type>::Value));
always_check((TIsSame<int32, TCopyReference<int32, int32 >::Type>::Value));
always_check((TIsSame<int32&, TCopyReference<int32, int32& >::Type>::Value));
always_check((TIsSame<int32&&, TCopyReference<int32, int32&&>::Type>::Value));
always_check((TIsSame<int32&, TCopyReference<int32&, int32 >::Type>::Value));
always_check((TIsSame<int32&, TCopyReference<int32&, int32& >::Type>::Value));
always_check((TIsSame<int32&, TCopyReference<int32&, int32&&>::Type>::Value));
always_check((TIsSame<int32&&, TCopyReference<int32&&, int32 >::Type>::Value));
always_check((TIsSame<int32&, TCopyReference<int32&&, int32& >::Type>::Value));
always_check((TIsSame<int32&&, TCopyReference<int32&&, int32&&>::Type>::Value));
always_check((TIsSame< int32, TCopyCVRef< int32, int32>::Type>::Value));
always_check((TIsSame<const int32, TCopyCVRef<const int32, int32>::Type>::Value));
always_check((TIsSame<const int32, TCopyCVRef< int32, const int32>::Type>::Value));
always_check((TIsSame<const int32, TCopyCVRef<const int32, const int32>::Type>::Value));
always_check((TIsSame< volatile int32, TCopyCVRef< volatile int32, int32>::Type>::Value));
always_check((TIsSame< volatile int32, TCopyCVRef< int32, volatile int32>::Type>::Value));
always_check((TIsSame< volatile int32, TCopyCVRef< volatile int32, volatile int32>::Type>::Value));
always_check((TIsSame<const int32, TCopyCVRef<const int32, int32>::Type>::Value));
always_check((TIsSame<const volatile int32, TCopyCVRef<const volatile int32, int32>::Type>::Value));
always_check((TIsSame<const int32, TCopyCVRef< int32, const int32>::Type>::Value));
always_check((TIsSame<const int32, TCopyCVRef<const int32, const int32>::Type>::Value));
always_check((TIsSame<const volatile int32, TCopyCVRef<const volatile int32, const int32>::Type>::Value));
always_check((TIsSame<const volatile int32, TCopyCVRef< int32, const volatile int32>::Type>::Value));
always_check((TIsSame<const volatile int32, TCopyCVRef<const int32, const volatile int32>::Type>::Value));
always_check((TIsSame<const volatile int32, TCopyCVRef<const volatile int32, const volatile int32>::Type>::Value));
always_check((TIsSame<int32, TCopyCVRef<int32, int32 >::Type>::Value));
always_check((TIsSame<int32&, TCopyCVRef<int32, int32& >::Type>::Value));
always_check((TIsSame<int32&&, TCopyCVRef<int32, int32&&>::Type>::Value));
always_check((TIsSame<int32&, TCopyCVRef<int32&, int32 >::Type>::Value));
always_check((TIsSame<int32&, TCopyCVRef<int32&, int32& >::Type>::Value));
always_check((TIsSame<int32&, TCopyCVRef<int32&, int32&&>::Type>::Value));
always_check((TIsSame<int32&&, TCopyCVRef<int32&&, int32 >::Type>::Value));
always_check((TIsSame<int32&, TCopyCVRef<int32&&, int32& >::Type>::Value));
always_check((TIsSame<int32&&, TCopyCVRef<int32&&, int32&&>::Type>::Value));
always_check((TIsSame<const int32, TCopyCVRef<const int32, int32 >::Type>::Value));
always_check((TIsSame<const int32&, TCopyCVRef< int32, const int32& >::Type>::Value));
always_check((TIsSame<const volatile int32&&, TCopyCVRef<const volatile int32, const int32&&>::Type>::Value));
always_check((TIsSame<const int32&, TCopyCVRef<const int32&, int32 >::Type>::Value));
always_check((TIsSame<const int32&, TCopyCVRef<const int32&, const int32& >::Type>::Value));
always_check((TIsSame<const volatile int32&, TCopyCVRef< volatile int32&, const int32&&>::Type>::Value));
always_check((TIsSame<const int32&&, TCopyCVRef<const int32&&, int32 >::Type>::Value));
always_check((TIsSame<const int32&, TCopyCVRef<const int32&&, const int32& >::Type>::Value));
always_check((TIsSame<const volatile int32&&, TCopyCVRef<const volatile int32&&, const int32&&>::Type>::Value));
} }
NAMESPACE_MODULE_END(Utility) NAMESPACE_MODULE_END(Utility)

View File

@ -0,0 +1,36 @@
#pragma once
#include "CoreTypes.h"
#include "TypeTraits/HelperClasses.h"
#include <type_traits>
NAMESPACE_REDCRAFT_BEGIN
NAMESPACE_MODULE_BEGIN(Redcraft)
NAMESPACE_MODULE_BEGIN(Utility)
template <typename From, typename To> struct TCopyConst { using Type = To; };
template <typename From, typename To> struct TCopyConst<const From, To> { using Type = const To; };
template <typename From, typename To> struct TCopyVolatile { using Type = To; };
template <typename From, typename To> struct TCopyVolatile<volatile From, To> { using Type = volatile To; };
template <typename From, typename To> struct TCopyCV { using Type = typename TCopyConst<From, typename TCopyVolatile<From, To>::Type>::Type; };
template <typename From, typename To> struct TCopyReference { using Type = To; };
template <typename From, typename To> struct TCopyReference<From&, To > { using Type = To&; };
template <typename From, typename To> struct TCopyReference<From&&, To > { using Type = To&&; };
template <typename From, typename To> struct TCopyCVRef { using Type = typename TCopyCV<From, To>::Type; };
template <typename From, typename To> struct TCopyCVRef<From, To& > { using Type = typename TCopyCV<From, To>::Type&; };
template <typename From, typename To> struct TCopyCVRef<From, To&&> { using Type = typename TCopyCV<From, To>::Type&&; };
template <typename From, typename To> struct TCopyCVRef<From&, To > { using Type = typename TCopyCV<From, To>::Type&; };
template <typename From, typename To> struct TCopyCVRef<From&, To& > { using Type = typename TCopyCV<From, To>::Type&; };
template <typename From, typename To> struct TCopyCVRef<From&, To&&> { using Type = typename TCopyCV<From, To>::Type&; };
template <typename From, typename To> struct TCopyCVRef<From&&, To > { using Type = typename TCopyCV<From, To>::Type&&; };
template <typename From, typename To> struct TCopyCVRef<From&&, To& > { using Type = typename TCopyCV<From, To>::Type&; };
template <typename From, typename To> struct TCopyCVRef<From&&, To&&> { using Type = typename TCopyCV<From, To>::Type&&; };
NAMESPACE_MODULE_END(Utility)
NAMESPACE_MODULE_END(Redcraft)
NAMESPACE_REDCRAFT_END

View File

@ -9,3 +9,4 @@
#include "TypeTraits/Miscellaneous.h" #include "TypeTraits/Miscellaneous.h"
#include "TypeTraits/Swappable.h" #include "TypeTraits/Swappable.h"
#include "TypeTraits/Common.h" #include "TypeTraits/Common.h"
#include "TypeTraits/CopyQualifiers.h"