jeudi 2 février 2017

Get the return type of begin on a c array

I would like to get the return type of std::begin in a generic way. My current solution is:

using type = decltype(std::begin(std::declval<T>()));

and it works when T = std::vector<int>. But I don't understand why the following does not work:

using type = decltype(std::begin(std::declval<int[3]>()));

I get the error:

example.cpp:83:60: error: no matching function for call to ‘begin(int [3])’
     using type = decltype(std::begin(std::declval<int[3]>()));

How to get the return type of std::begin in a generic way?

Aucun commentaire:

Enregistrer un commentaire