Discussion
According to the standard §20.10.2/1 Header <type_traits>
synopsis [meta.type.synop]:
1
The behavior of a program that adds specializations for any of the class templates defined in this subclause is undefined unless otherwise specified.
This specific clause contradicts to the general notion that STL should be expandible and prevents us from expanding type traits as in the example below:
namespace std {
template< class T >
struct is_floating_point<std::complex<T>> : std::integral_constant
<
bool,
std::is_same<float, typename std::remove_cv<T>::type>::value ||
std::is_same<double, typename std::remove_cv<T>::type>::value ||
std::is_same<long double, typename std::remove_cv<T>::type>::value
> {};
}
where std::is_floating_point
is expanded to handle complex
number with underlying floating point type as well.
Questions
- What are the reasons that made the standardization committee decide that type-traits should not be specialized.
- Are there any future plans for this restriction to be retracted.
struct is_floating_point<std::complex<T>> : public std::is_floating::point<T> {};
?std::is_floating_point
and making your entire translation unit considerstd::complex
to be a floating point type just so you can do a check of "isstd::complex
or floating point" in one of your functions is like blowing up your house to get some fresh air inside. The type trait classes query fundamental properties of types and are the basic building blocks for template metaprograms. It makes little sense to allow you to add specializations for them.