A C++ template library for embedded applications
MIT licensed
Designed and
maintained by
John Wellbelove
Support the development
of the ETL

Parameter

Pack
Compile time mapping of index to type and type to index for a template parameter pack.
For C++11 or above
____________________________________________________________________________________________________
parameter_pack

template <typename... TTypes>
class parameter_pack

Defines
static constexpr size_t size = sizeof...(TTypes);

The class contains two nested templates.
____________________________________________________________________________________________________
index_of_type

template <typename T>
class index_of_type

For C++17 or above
template <typename T>
static constexpr size_t index_of_type_v = index_of_type<T>::value;

____________________________________________________________________________________________________
type_from_index

template <size_t I>
class type_from_index

template <size_t I>
using type_from_index_t = typename type_from_index<I>::type;
____________________________________________________________________________________________________
Examples

using Pack = etl::parameter_pack<char, short, int>;

constexpr size_t size = Pack::size; // size == 3

size_t indexChar  = Pack::index_of_type_v<char>;   // indexChar  == 0
size_t indexShort = Pack::index_of_type_v<short>;  // indexShort == 1
size_t indexInt   = Pack::index_of_type_v<int>;    // indexInt   == 2
size_t indexLong  = Pack::index_of_type_v<long>;   // Static assert
                                                   // "T is not in parameter pack"

using type0 = typename Pack::type_from_index_t<0>; // type0 = char
using type1 = typename Pack::type_from_index_t<1>; // type1 = short
using type2 = typename Pack::type_from_index_t<2>; // type2 = int
using type3 = typename Pack::type_from_index_t<3>; // Static assert
                                                   // "Index out of bounds of parameter pack"
parameter_pack.h