mardi 24 février 2015

Why do all type_traits Classes have to be called using 'typename' and '::type' Prefix/Suffix?

This is kind of an odd question although it is pretty obvious:


Why do all templates in <type_traits> have to be called with typenname and ::type prefix/suffix?


One reason would be, of course, that there was no templated typedef like the C++0x using thingy, that allows the following:



template<typename T>
using remove_ref = typename std::remove_reference<T>::type;

remove_ref<int&> foo = 4;


So this question is less about, why it currently is that way, but more about whether this behaviour is going to be simplified in future C++ standards?.


Similar improvement could come with traits like std::is_pointer<T>::value - I can already see templated constants at the horizon of C++14/17 that would allow uses like std::is_pointer<T>.


Note: To my knowledge, this simplification is not subject of any of the published items concerning the upcoming C++ standards. In this case, there is no real yes/no answer to this question and this thread could act as a pro/con list whether this is likely to be changed in any new versions of C++.


Aucun commentaire:

Enregistrer un commentaire