其中< type_traits>无法实现没有编译器钩子? [英] Which <type_traits> cannot be implemented without compiler hooks?
问题描述
C ++ 11提供标准< type_traits>
。
C++11 provides standard <type_traits>
.
其中哪些不可能无需编译器挂钩即可实现?
Which of them are impossible to implement without compiler hooks?
- 注意1:通过编译器挂钩我是指任何非标准的语言功能,如
__ is_builtin ...
。 - 注意2:其中许多可以无钩子实现(请参阅 C ++模板元编程的第2章和/或第2章< a href =http://rads.stackoverflow.com/amzn/click/0201704315>现代C ++设计)。
- 注意3: spraff answer 在此前问题中引用 N2984 其中某些类型特征包含以下注释:据信需要编译器支持 (感谢sehe)。
- Note 1: by compiler hook I mean any non-standard language feature such as
__is_builtin...
. - Note 2: a lot of them can be implemented without hooks (see chapter 2 of C++ Template Metaprogramming and/or chapter 2 of Modern C++ Design).
- Note 3: spraff answer in this previous question cites N2984 where some type traits contain the following note: is believed to require compiler support (thanks sehe).
推荐答案
每最后 boost文档,它也有点旧,但我认为它仍然有效
Per lastest boost documentation which is also a bit old but I think it's valid still
有一些特性不能在当前C ++语言中实现:使这些特性 使用用户定义的类型,需要从编译器得到某种额外的帮助。目前(2008年4月)Visual C ++ 8和9,GNU GCC 4.3和MWCW 9提供了至少一些必要的内在函数,其他编译器无疑会在适当时候遵循。
There are some traits that can not be implemented within the current C++ language: to make these traits "just work" with user defined types, some kind of additional help from the compiler is required. Currently (April 2008) Visual C++ 8 and 9, GNU GCC 4.3 and MWCW 9 provide at least some of the the necessary intrinsics, and other compilers will no doubt follow in due course.
以下traits类始终需要编译器支持为所有类型执行正确的操作(但如果此支持不可用,则所有类型都具有安全的后备位置):
The Following traits classes always need compiler support to do the right thing for all types (but all have safe fallback positions if this support is unavailable):
is_union
is_pod
has_trivial_constructor
has_trivial_copy
has_trivial_move_constructor
has_trivial_assign
has_trivial_move_assign
has_trivial_destructor
has_nothrow_constructor
has_nothrow_copy
has_nothrow_assign
has_virtual_destructor
以下traits类不能可移植地用C ++语言实现,尽管在实践中,实现在我们所知的所有编译器上都做正确的事情:
The following traits classes can't be portably implemented in the C++ language, although in practice, the implementations do in fact do the right thing on all the compilers we know about:
is_empty
is_polymorphic
以下traits类依赖于一个或多个上述:
The following traits classes are dependent on one or more of the above:
is_class
这篇关于其中< type_traits>无法实现没有编译器钩子?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!