2016-07-20 57 views
1

如何使用GCC 6.1檢測Concepts TS的存在?使用GCC 6.1檢測概念TS

This page建議宏__cpp_experimental_concepts應該在支持Concepts TS的實現中預定義。但是,下面的測試程序沒有錯誤編譯的GCC 6.1與-fconcepts標誌:

#ifdef __cpp_experimental_concepts 
static_assert(false, "Concepts TS found"); 
#endif 

template <typename T> 
concept bool Identity = true; 

int main() {} 

(我希望無論是static_assert火,或concept關鍵字去無法識別)

有誰知道任何其他方法來基於Concepts是否可用來有條件地編譯代碼?

+3

你可以用'echo | g ++ -E -dM -fconcepts -x C++ - | fgrep概念' –

回答

4

正確的宏__cpp_concepts爲GCC:

#ifdef __cpp_concepts 
static_assert(false, "Concepts TS found"); 
#endif 

this,宏的名字在最近的草案改變。

正確的名稱是從GCC support page(感謝Jonathan Wakely),但linked draft(2015年2月9日)仍然需要__cpp_experimental_concepts(這是奇怪的...)。但是,在此more recent draft(2015-09-25)中,名稱實際上已更改爲__cpp_concepts

+0

奇怪的是,考慮到它仍然是一個TS,它不再被認爲是實驗,但這正是我所需要的 - 非常感謝您的快速反應。 –

+4

該宏及其官方價值記錄在https://gcc.gnu.org/projects/cxx-status.html#tses(g ++似乎現在設置爲201500而不是201507) –

+0

@JonathanWakely看起來像是有一個因爲這個值來自於'__cpp_experimental_concepts'仍在使用的舊草案。 – Holt