chr*_*ris 8 c++ variable-templates c++14
随着C++ 14中的变量模板(以及Clang已经支持它们)和标准is_same_v类型特征的提议,我认为能够制作新的类型特征如下:
template<typename T>
constexpr bool is_const_and_volatile{std::is_const_v<T> && std::is_volatile_v<T>};
Run Code Online (Sandbox Code Playgroud)
唉,这会导致错误等同于以下SSCCE(这个包含下面提到的所有内容):
#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 *>;
}
Run Code Online (Sandbox Code Playgroud)
在main评论中,Clang吐出以下内容:
警告:变量
is_pointer<type-parameter-0-0>具有内部链接但未定义
它看起来定义为我的(注意,更改T到int *在foo正常工作).在取消注释行main实例foo给出了这样的(再次,T以int *优良工程):
错误:constexpr变量
foo<int *>必须由常量表达式初始化
但是,foo使用以下旧语法替换会导致两个实例都正常工作:
constexpr bool foo{std::is_pointer<T>::value};
Run Code Online (Sandbox Code Playgroud)
关于变量模板有什么我想念的吗?有没有办法用它们构建新的变量模板,或者我是否被迫使用旧的语法来构建新的模板,并且在将它们用于其他代码时只享受语法糖?