提问人:kfmfe04 提问时间:12/17/2012 最后编辑:kfmfe04 更新时间:4/9/2015 访问量:462
::std::has_nothrow_default_constructor是否被移动/更改?
has ::std::has_nothrow_default_constructor been moved/changed?
问:
在尝试使用 gcc 4.7.2 构建升压镜像时,我遇到了这个错误,但奇怪的是,我看到了这个文档。
::std::has_nothrow_default_constructor
是否被移动/更改?
In file included from /home/kfeng/src/mirror-lib/include/mirror/type_traits.hpp:20:0,
from /home/kfeng/src/mirror-lib/include/mirror/mirror_base.hpp:38,
from /home/kfeng/src/mirror-lib/include/mirror/mirror.hpp:16,
from /home/kfeng/src/mirror-lib/src/mirror/example/all_member_variables.cpp:10:
/home/kfeng/src/mirror-lib/include/mirror/type_traits/is_default_constructible.hpp:31:2: error: ‘has_nothrow_default_constructor’ is not a member of ‘std’
/home/kfeng/src/mirror-lib/include/mirror/type_traits/is_default_constructible.hpp:28:9: error: parse error in template argument list
/home/kfeng/src/mirror-lib/include/mirror/type_traits/is_default_constructible.hpp:31:43: error: expected ‘{’ before ‘::’ token
/home/kfeng/src/mirror-lib/include/mirror/type_traits/is_default_constructible.hpp:31:51: error: expected initializer before ‘||’ token
In file included from /home/kfeng/src/mirror-lib/include/mirror/type_traits.hpp:21:0,
from /home/kfeng/src/mirror-lib/include/mirror/mirror_base.hpp:38,
from /home/kfeng/src/mirror-lib/include/mirror/mirror.hpp:16,
from /home/kfeng/src/mirror-lib/src/mirror/example/all_member_variables.cpp:10:
/home/kfeng/src/mirror-lib/include/mirror/type_traits/is_copy_constructible.hpp:31:2: error: ‘has_nothrow_copy_constructor’ is not a member of ‘std’
/home/kfeng/src/mirror-lib/include/mirror/type_traits/is_copy_constructible.hpp:28:9: error: parse error in template argument list
/home/kfeng/src/mirror-lib/include/mirror/type_traits/is_copy_constructible.hpp:31:40: error: expected ‘{’ before ‘::’ token
/home/kfeng/src/mirror-lib/include/mirror/type_traits/is_copy_constructible.hpp:31:48: error: expected initializer before ‘||’ token
make[2]: *** [src/mirror/example/CMakeFiles/mirror-all_member_variables.dir/all_member_variables.cpp.o] Error 1
make[1]: *** [src/mirror/example/CMakeFiles/mirror-all_member_variables.dir/all] Error 2
make: *** [all] Error 2
使用下面的 Pubby 注释回答
像这样的东西应该适用于 gcc 4.7.2 - 我将提交一个补丁,让维护者决定如何最好地处理它。
template <typename T>
struct is_default_constructible
: std::integral_constant<
bool,
::std::has_trivial_default_constructor<T>::value ||
#if __cplusplus>=201103L
::std::is_nothrow_default_constructible<T>::value ||
#else
::std::has_nothrow_default_constructor<T>::value ||
#endif
mirror::_class::_<T>::has_default_ctr::value>
{ };
答:
6赞
Pubby
12/17/2012
#1
在 C++11 中,它被更改为与命名更加一致。std::is_nothrow_default_constructible
评论
0赞
kfmfe04
12/17/2012
+1 tyvm - 我将编辑代码并尝试一下 - 快速撇开,必须有一个我可以用来检查是否已传入......去谷歌找它#ifdef
--std=c++11
0赞
Pubby
12/17/2012
@kfmfe04 你可以只使用boost::has_nothrow_default_constructor
0赞
Pubby
12/17/2012
@kfmfe04 此外,是您可以检查的宏,尽管它可能无法保证特征存在。__cplusplus
1赞
Jonathan Wakely
12/17/2012
#2
您正在查看 GCC 4.6.2 的文档,但使用的是 GCC 4.7.2,因此它们不匹配也就不足为奇了。
这些性状由 n3142 重命名
请参阅我的 https://stackoverflow.com/a/12716778/981959 的先前答案,以获取一些尝试检测您的编译器支持的代码,尽管评论说它不适用于 libc++。
评论