From 3150e07f6bf53fbb360ae3c85a6935aa7b1d3fa5 Mon Sep 17 00:00:00 2001 From: _Redstone_c_ Date: Wed, 23 Mar 2022 17:50:55 +0800 Subject: [PATCH] feat(templates): add TIntegerSequence and the corresponding testing --- .../Source/Public/Templates/IntegerSequence.h | 66 +++++++++++++++++++ .../Source/Public/Templates/Templates.h | 1 + 2 files changed, 67 insertions(+) create mode 100644 Redcraft.Utility/Source/Public/Templates/IntegerSequence.h diff --git a/Redcraft.Utility/Source/Public/Templates/IntegerSequence.h b/Redcraft.Utility/Source/Public/Templates/IntegerSequence.h new file mode 100644 index 0000000..84a2706 --- /dev/null +++ b/Redcraft.Utility/Source/Public/Templates/IntegerSequence.h @@ -0,0 +1,66 @@ +#pragma once + +#include "CoreTypes.h" + +NAMESPACE_REDCRAFT_BEGIN +NAMESPACE_MODULE_BEGIN(Redcraft) +NAMESPACE_MODULE_BEGIN(Utility) + +template +struct TIntegerSequence +{ + using ValueType = T; + static constexpr size_t Size() { return sizeof...(Ints); } +}; + +NAMESPACE_PRIVATE_BEGIN + +#ifdef _MSC_VER + +template +struct TMakeIntegerSequence +{ + using Type = typename __make_integer_seq; +}; + +#elif __has_builtin(__make_integer_seq) + +template +struct TMakeIntegerSequence +{ + using Type = typename __make_integer_seq; +}; + +#else + +template +struct TMakeIntegerSequence +{ + using Type = typename TMakeIntegerSequence::Type; +}; + +template +struct TMakeIntegerSequence<0, T, Ints...> +{ + using Type = TIntegerSequence; +}; + +#endif + +NAMESPACE_PRIVATE_END + +template +using TIndexSequence = TIntegerSequence; + +template +using TMakeIntegerSequence = typename NAMESPACE_PRIVATE::TMakeIntegerSequence::Type; + +template +using TMakeIndexSequence = TMakeIntegerSequence; + +template +using TIndexSequenceFor = TMakeIndexSequence; + +NAMESPACE_MODULE_END(Utility) +NAMESPACE_MODULE_END(Redcraft) +NAMESPACE_REDCRAFT_END diff --git a/Redcraft.Utility/Source/Public/Templates/Templates.h b/Redcraft.Utility/Source/Public/Templates/Templates.h index 5024671..d18d47c 100644 --- a/Redcraft.Utility/Source/Public/Templates/Templates.h +++ b/Redcraft.Utility/Source/Public/Templates/Templates.h @@ -9,3 +9,4 @@ #include "Templates/Optional.h" #include "Templates/Variant.h" #include "Templates/Any.h" +#include "Templates/IntegerSequence.h"