From 0dbbc4ba57b414933083b8d247063a8e7252c152 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sun, 10 Nov 2024 10:10:10 +0000 Subject: [PATCH] Updated nth_type to handle a type list of zero length --- include/etl/nth_type.h | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/include/etl/nth_type.h b/include/etl/nth_type.h index f870bb7c..5bc1e836 100644 --- a/include/etl/nth_type.h +++ b/include/etl/nth_type.h @@ -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 + struct nth_type; + + //*************************************************************************** + /// Finds the nth type in a variadic type parameter. + //*************************************************************************** template - struct nth_type + struct nth_type { + ETL_STATIC_ASSERT(N <= sizeof...(TRest), "etl::nth_type out of range for type list"); + using type = typename nth_type::type; }; + //*************************************************************************** + /// Finds the 0thth type in a variadic type parameter. + //*************************************************************************** template struct nth_type<0U, T1, TRest...> { using type = T1; }; + //*************************************************************************** + /// Finds the 0thth type in a variadic type parameter. + //*************************************************************************** + template + struct nth_type + { + }; + + //*************************************************************************** + /// Finds the nth type in a variadic type parameter. + //*************************************************************************** template using nth_type_t = typename nth_type::type; #endif