use*_*285 16 c++ type-traits c++11
我的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'.
这有什么问题?它们甚至得到当前海湾合作委员会的支持吗?谢谢!
Kip*_*ros 14
正如其他人所提到的,GCC版本<5不支持std::is_trivially_copyableC++ 11标准.
这是一个有点解决这个限制的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
Run Code Online (Sandbox Code Playgroud)
对于常见情况,此hack可能足以让您的代码正常工作.但要注意GCC 和GCC之间的细微差别.欢迎提出改进建议.__has_trivial_copystd::is_trivially_copyable
Bil*_*nch 12
其中一些没有实施.如果我们看一下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";
}
Run Code Online (Sandbox Code Playgroud)
[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
Run Code Online (Sandbox Code Playgroud)
GCC(在本例中为libstdc ++)根据类型特征的早期版本的标准化提议,实现了具有不同非标准名称的多个类型特征.特别:
std::has_trivial_copy_constructor<int>::value
Run Code Online (Sandbox Code Playgroud)
这只提供了完整实现std::is_trivially_copyable所提供的信息的一部分,因为有一个简单的拷贝构造函数是必要的,但对于一个简单的可复制类型是不够的.