feat(templates): add TIntegerSequence and the corresponding testing

This commit is contained in:
_Redstone_c_ 2022-03-23 17:50:55 +08:00
parent 0c6bf06a56
commit 3150e07f6b
2 changed files with 67 additions and 0 deletions

View File

@ -0,0 +1,66 @@
#pragma once
#include "CoreTypes.h"
NAMESPACE_REDCRAFT_BEGIN
NAMESPACE_MODULE_BEGIN(Redcraft)
NAMESPACE_MODULE_BEGIN(Utility)
template <typename T, T... Ints>
struct TIntegerSequence
{
using ValueType = T;
static constexpr size_t Size() { return sizeof...(Ints); }
};
NAMESPACE_PRIVATE_BEGIN
#ifdef _MSC_VER
template <unsigned N, typename T>
struct TMakeIntegerSequence
{
using Type = typename __make_integer_seq<TIntegerSequence, T, N>;
};
#elif __has_builtin(__make_integer_seq)
template <unsigned N, typename T>
struct TMakeIntegerSequence
{
using Type = typename __make_integer_seq<TIntegerSequence, T, N>;
};
#else
template <unsigned N, typename T, T... Ints>
struct TMakeIntegerSequence
{
using Type = typename TMakeIntegerSequence<N - 1, T, T(N - 1), Ints...>::Type;
};
template <typename T, T... Ints>
struct TMakeIntegerSequence<0, T, Ints...>
{
using Type = TIntegerSequence<T, Ints...>;
};
#endif
NAMESPACE_PRIVATE_END
template <size_t... Ints>
using TIndexSequence = TIntegerSequence<size_t, Ints...>;
template<typename T, T N>
using TMakeIntegerSequence = typename NAMESPACE_PRIVATE::TMakeIntegerSequence<N, T>::Type;
template<size_t N>
using TMakeIndexSequence = TMakeIntegerSequence<size_t, N>;
template<typename... T>
using TIndexSequenceFor = TMakeIndexSequence<sizeof...(T)>;
NAMESPACE_MODULE_END(Utility)
NAMESPACE_MODULE_END(Redcraft)
NAMESPACE_REDCRAFT_END

View File

@ -9,3 +9,4 @@
#include "Templates/Optional.h"
#include "Templates/Variant.h"
#include "Templates/Any.h"
#include "Templates/IntegerSequence.h"