我去看看你是否可以在变量模板声明中使用auto。
template <typename T>
auto F = T{};好的,但是一旦你想用它,就去玩吧。
int f = F<int>; // error: cannot initialize a variable of type 'int' with an lvalue of type 'auto'
auto f = F<int>; // Stacktrace
decltype(F<int>) f = F<int>; // StackFace
std::cout << std::is_same<int, decltype(F<int>)>::value; // false
std::cout << typeid(decltype(F<int>)).name(); // Stacktrace
std::cout << std::is_same<decltype(F<int>), decltype(F<int>)>::value; // true任何decltype(auto)的组合,auto都不能工作,即使它说auto是一个左值。
int f = static_cast<int>(F<int>); // error: static_cast from 'auto' to 'int' is not allowed我从来没有见过汽车公司这样做过。是因为变量模板,还是因为clang对待auto的方式?
发布于 2014-02-16 08:19:26
这似乎在最新版本的clang中得到了解决;将其放入一个文件中并调用
clang++ -std=c++1y test.cpp不会给我任何错误。
kevinushey@Kevin-MBP:~$ clang++ -v
clang version 3.5 (trunk 201469)
Target: x86_64-apple-darwin13.0.0
Thread model: posixhttps://stackoverflow.com/questions/21802507
复制相似问题