With variable templates included in C ++ 14 (and Clang already supporting them) and a proposal for standard is_same_v and similar types, I figured it was possible to create new type traits like this:
template<typename T> constexpr bool is_const_and_volatile{std::is_const_v<T> && std::is_volatile_v<T>};
Alas, this leads to errors equivalent to the following SSCCE ( this one contains everything below):
#include <type_traits> template<typename T> constexpr bool is_pointer{std::is_pointer<T>::value}; template<typename T> constexpr bool foo{is_pointer<T>}; int main() { //foo<int *>; }
When reading a line in main Clang, it spits out the following:
warning: the variable is_pointer<type-parameter-0-0> has an internal relationship but is not defined
It looks specific to me (note that changing T to int * in foo works fine). Uncommenting the line in main to instantiate foo gives this (again, from T to int * works fine):
error: constexpr constant foo<int *> must be initialized with a constant expression
However, replacing foo with the following old syntax makes both instances work fine:
constexpr bool foo{std::is_pointer<T>::value};
Is there something I am missing in variable templates? Is there a way to create new variable templates with them, or am I forced to use the old syntax to create new ones and use syntactic sugar only when using them for other code?
c ++ c ++ 14 variable-templates
chris
source share