Similar question: Why are
type_traits
implemented with specialized template structs instead of constexpr? – but with a different answer.
I realise that alias templates cannot be specialised and hence can’t currently be used to implement type traits directly1. However, this is a conscious decision of the committee, and as far as I see there is no technical reason to forbid this.
So wouldn’t it have made more sense to implement type traits as alias templates, streamlining their syntax?
Consider
typename enable_if<is_pointer<T>::value, size_t>::type
address(T p);
versus
enable_if<is_pointer<T>, size_t> address(T p);
Of course, this introduces a breaking interface change when moving from Boost.TypeTraits – but is this really such a big problem?
After all, the code will need to be modified anyway since the types reside in different namespace and, as many modern C++ programmers are reluctant to open namespaces, will be qualified explicitly (if it would be changed at all).
On the other hand, it vastly simplifies the code. And given that template metaprogramming often gets deeply nested, convoluted and complex, it seems obvious that a clearer interface is beneficial.
Am I missing something? If not, I’d appreciate an answer that is not mere guesswork but relies on (and can cite) knowledge of the committee’s decision rationale.
1 But very well indirectly! Consider:
template <typename T> using is_pointer = typename meta::is_pointer<T>::type;
Where meta::is_pointer<T>
corresponds to the current std::is_pointer<T>
type.