dimanche 21 août 2022

How to get first element of typelist in C++-11

I am following C++ templates the complete guide and trying to get the first element from a typelist.

The following compiles:

#include <bits/stdc++.h>

using namespace std;

template <typename... Elements>
class Typelist;

using SignedIntegralTypes =
        Typelist<signed char, short, int, long, long long>;

template <typename List>
class HeadT;

template <typename Head, typename... Tail>
class HeadT<Typelist<Head, Tail...>> {
public:
    using Type = Head;
};

template <typename List>
using Head = typename HeadT<Typelist<List>>::Type;


int main() {
    static_assert(is_same<Head<SignedIntegralTypes>, SignedIntegralTypes>::value, "");
}

Head<SignedIntegralTypes> produces SignedIntegralTypes. I would expect it to produce signed char. Why is this happening? How do I fix it?

Aucun commentaire:

Enregistrer un commentaire