2011-10-09 60 views
3

我試圖讓模板別名對鐺工作,但它不工作雖然reference sheet說,它確實模板別名不工作

~~~~>$ cat template_alias.cpp 
#include <vector> 

using namespace std; 

template<typename T> 
using DoubleVec = vector<vector<T>>; 

int main() { return 0; } 

~~~~>$ clang template_alias.cpp -o template_alias 

template_alias.cpp:6:19: warning: alias declarations accepted as a C++0x extension [-Wc++0x-extensions] 
using DoubleVec = vector<vector<T>>; 
       ^
template_alias.cpp:6:34: error: a space is required between consecutive right angle brackets (use '> >') 
using DoubleVec = vector<vector<T>>; 
           ^~ 
           > > 
template_alias.cpp:6:1: error: cannot template a using declaration 
using DoubleVec = vector<vector<T>>; 
^ 
1 warning and 2 errors generated. 

~~~~>$ clang -std=c++0x template_alias.cpp -o template_alias 

template_alias.cpp:6:1: error: cannot template a using declaration 
using DoubleVec = vector<vector<T>>; 
^ 
1 error generated. 

我是不是做錯了?

+0

我不知道,在這一點上支持模板別名任何編譯器... –

回答

7

你的第二個命令(帶-std = C++ 0x)是正確的,就像你的測試用例一樣。在支持模板別名之前,您可能會使用鏗鏘的版本。您可以通過執行檢查這個:

#if __has_feature(cxx_alias_templates) 

這裏是功能測試宏的完整列表鐺用途:

http://clang.llvm.org/docs/LanguageExtensions.html#checking_upcoming_features

這裏是一個,有點不愉快,方式應對

#include <vector> 

using namespace std; 

#if __has_feature(cxx_alias_templates) 

template<typename T> 
using DoubleVec = vector<vector<T>>; 

#else 

template<typename T> 
struct DoubleVec { 
    typedef vector<vector<T> > type; 
}; 

#endif 

int main() 
{ 
#if __has_feature(cxx_alias_templates) 
    DoubleVec<int> v; 
#else 
    DoubleVec<int>::type v; 
#endif 
} 
+0

我有:支持模板別名,而不是之間的過渡期最新版本的Xcode – Dani

+0

在商業項目中發佈什麼是滯後於開源項目的主幹的是正常的。 –

+0

你知道有什麼方法可以在xCode中更新clang嗎?它仍然能夠編譯爲iphone並通過應用商店批准? – Dani