mirror of
https://github.com/ETLCPP/etl.git
synced 2026-11-09 14:49:53 +08:00
Updated nth_type to handle a type list of zero length
This commit is contained in:
parent
07333fd1dd
commit
748e2357f5
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user