Updated nth_type to handle a type list of zero length

This commit is contained in:
John Wellbelove 2024-11-10 10:10:10 +00:00
parent 07333fd1dd
commit 748e2357f5

View File

@ -30,22 +30,49 @@ SOFTWARE.
#define ETL_NTH_TYPE_INCLUDED
#include "platform.h"
#include "static_assert.h"
namespace etl
{
#if ETL_USING_CPP11
//***************************************************************************
/// Finds the nth type in a variadic type parameter.
//***************************************************************************
template <size_t N, typename... TTypes>
struct nth_type;
//***************************************************************************
/// Finds the nth type in a variadic type parameter.
//***************************************************************************
template <size_t N, typename T1, typename... TRest>
struct nth_type
struct nth_type<N, T1, TRest...>
{
ETL_STATIC_ASSERT(N <= sizeof...(TRest), "etl::nth_type out of range for type list");
using type = typename nth_type<N - 1U, TRest...>::type;
};
//***************************************************************************
/// Finds the 0thth type in a variadic type parameter.
//***************************************************************************
template <typename T1, typename... TRest>
struct nth_type<0U, T1, TRest...>
{
using type = T1;
};
//***************************************************************************
/// Finds the 0thth type in a variadic type parameter.
//***************************************************************************
template <size_t N>
struct nth_type<N>
{
};
//***************************************************************************
/// Finds the nth type in a variadic type parameter.
//***************************************************************************
template <size_t N, typename... TTypes>
using nth_type_t = typename nth_type<N, TTypes...>::type;
#endif