[英]‘is_trivially_copyable’ is not a member of ‘std’
我的gcc版本是4.8.3 20140624.我可以使用is_pod
, is_trivial
, is_standard_layout
,但在嘗試is_trivially_copyable
, is_constructible
和is_default_constructible
時可能會失敗。 錯誤消息'xxx' is not a member of 'std'
。
這有什么問題? 它們甚至得到當前海灣合作委員會的支持嗎? 謝謝!
正如其他人所提到的,GCC版本<5不支持C ++ 11標准中的std::is_trivially_copyable
。
這是一個有點解決這個限制的hack:
// workaround missing "is_trivially_copyable" in g++ < 5.0
#if __GNUG__ && __GNUC__ < 5
#define IS_TRIVIALLY_COPYABLE(T) __has_trivial_copy(T)
#else
#define IS_TRIVIALLY_COPYABLE(T) std::is_trivially_copyable<T>::value
#endif
對於常見情況,此hack可能足以讓您的代碼正常工作。 但要注意GCC的__has_trivial_copy
和std::is_trivially_copyable
之間的細微差別 。 歡迎提出改進建議。
其中一些沒有實施。 如果我們看一下libstdc ++的c ++ 11狀態頁面 :
類型屬性列為部分實現 。
他們列為缺失:
is_constructible
和is_default_constructible
應該可用。 我可以在GCC 4.8.2中成功使用它們。
#include <type_traits>
#include <iostream>
int main() {
std::cout << std::is_constructible<int>::value << "\n";
std::cout << std::is_default_constructible<int>::value << "\n";
}
[11:47am][wlynch@apple /tmp] /opt/gcc/4.8.2/bin/g++ -std=c++11 foo.cc
[11:47am][wlynch@apple /tmp] ./a.out
1
1
GCC(在本例中為libstdc ++)根據類型特征的早期版本的標准化提議,實現了具有不同非標准名稱的多個類型特征。 特別:
std::has_trivial_copy_constructor<int>::value
這只提供了std::is_trivially_copyable
的完整實現所提供的信息的一部分,因為有一個簡單的拷貝構造函數是必要的,但對於一個簡單的可復制類型是不夠的。
僅供參考,這些特性現已實施,將在GCC 5中發布。
實際上,GCC的C ++ 2011實現似乎不支持'is_trivially_copyable'。 見狀態的第20.9.4.3點
您可以嘗試安裝Clang3.4並使用選項-std = c ++ 1y進行編譯
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.