feat(templates): add TUnwrapReference and the corresponding testing

This commit is contained in:
_Redstone_c_ 2022-03-26 19:33:28 +08:00
parent e1871de73b
commit 91755d2196
2 changed files with 8 additions and 0 deletions

View File

@ -75,6 +75,9 @@ void TestReferenceWrapper()
always_check(ArrayA[0] == 2); always_check(ArrayA[0] == 2);
always_check(ArrayA[1] == 4); always_check(ArrayA[1] == 4);
always_check(ArrayA[2] == 6); always_check(ArrayA[2] == 6);
always_check((TIsSame<int32, TUnwrapRefDecay<int32>::Type>::Value));
always_check((TIsSame<int32&, TUnwrapRefDecay<TReferenceWrapper<int32>>::Type>::Value));
} }
void TestOptional() void TestOptional()

View File

@ -40,6 +40,11 @@ private:
template <typename T> template <typename T>
TReferenceWrapper(T&) -> TReferenceWrapper<T>; TReferenceWrapper(T&) -> TReferenceWrapper<T>;
template <typename T> struct TUnwrapReference { using Type = T; };
template <typename T> struct TUnwrapReference<TReferenceWrapper<T>> { using Type = T&; };
template <typename T> struct TUnwrapRefDecay { using Type = typename TUnwrapReference<typename TDecay<T>::Type>::Type; };
NAMESPACE_MODULE_END(Utility) NAMESPACE_MODULE_END(Utility)
NAMESPACE_MODULE_END(Redcraft) NAMESPACE_MODULE_END(Redcraft)
NAMESPACE_REDCRAFT_END NAMESPACE_REDCRAFT_END