mardi 24 mai 2016

Is there a way to deduce a type of a single element of an array in c++

I'm having problem with deducing a type of a single element of an c++ array.

I would like to do achieve something like:

template <class T>
struct array_element { };

template <class T>
struct array_element<T[]> {
   using type = T;
};

int main() {
   int a[5] = {1, 2, 3, 4, 5};
   array_element<decltype(a)>::type element = a[0];
}

But the code obviously does not compile (the int[5] does not match T[])...

Aucun commentaire:

Enregistrer un commentaire