Brian Silverman | 4a2409e | 2018-08-04 23:24:02 -0700 | [diff] [blame^] | 1 | [/ |
| 2 | Copyright 2007 John Maddock. |
| 3 | Distributed under the Boost Software License, Version 1.0. |
| 4 | (See accompanying file LICENSE_1_0.txt or copy at |
| 5 | http://www.boost.org/LICENSE_1_0.txt). |
| 6 | ] |
| 7 | |
| 8 | [section:intrinsics Support for Compiler Intrinsics] |
| 9 | |
| 10 | There are some traits that can not be implemented within the current C++ language: |
| 11 | to make these traits "just work" with user defined types, some kind of additional |
| 12 | help from the compiler is required. Currently (April 2008) Visual C++ 8 and 9, |
| 13 | GNU GCC 4.3 and MWCW 9 provide at least some of the the necessary intrinsics, |
| 14 | and other compilers will no doubt follow in due course. |
| 15 | |
| 16 | The Following traits classes always need compiler support to do the right thing |
| 17 | for all types |
| 18 | (but all have safe fallback positions if this support is unavailable): |
| 19 | |
| 20 | * __is_final |
| 21 | * __is_union |
| 22 | * __is_pod |
| 23 | * __is_nothrow_move_assignable |
| 24 | * __is_nothrow_move_constructible |
| 25 | * __has_trivial_constructor |
| 26 | * __has_trivial_copy |
| 27 | * __has_trivial_move_constructor |
| 28 | * __has_trivial_assign |
| 29 | * __has_trivial_move_assign |
| 30 | * __has_trivial_destructor |
| 31 | * __has_nothrow_constructor |
| 32 | * __has_nothrow_copy |
| 33 | * __has_nothrow_assign |
| 34 | * __has_virtual_destructor |
| 35 | |
| 36 | The following traits classes can't be portably implemented in the C++ language, |
| 37 | although in practice, the implementations do in fact do the right thing on all |
| 38 | the compilers we know about: |
| 39 | |
| 40 | * __is_empty |
| 41 | * __is_polymorphic |
| 42 | * __is_virtual_base_of |
| 43 | |
| 44 | The following traits classes are dependent on one or more of the above: |
| 45 | |
| 46 | * __is_class |
| 47 | * __is_stateless |
| 48 | |
| 49 | The hooks for compiler-intrinsic support are defined in |
| 50 | [@../../../../boost/type_traits/intrinsics.hpp boost/type_traits/intrinsics.hpp], adding support for new compilers is simply |
| 51 | a matter of defining one of more of the following macros: |
| 52 | |
| 53 | [table Macros for Compiler Intrinsics |
| 54 | [[BOOST_ALIGNMENT_OF(T)][Should evaluate to the alignment requirements of type T]] |
| 55 | [[BOOST_IS_ABSTRACT(T)][Should evaluate to true if T is an abstract type]] |
| 56 | [[BOOST_IS_BASE_OF(T,U)][Should evaluate to true if T is a base class of U]] |
| 57 | [[BOOST_IS_CLASS(T)][Should evaluate to true if T is a class type]] |
| 58 | [[BOOST_IS_CONVERTIBLE(T,U)][Should evaluate to true if T is convertible to U]] |
| 59 | [[BOOST_IS_EMPTY(T)][Should evaluate to true if T is an empty struct or union]] |
| 60 | [[BOOST_IS_ENUM(T)][Should evaluate to true is T is an enum]] |
| 61 | [[BOOST_IS_FINAL(T)][Should evaluate to true if T is a class type declared with the final specifier]] |
| 62 | [[BOOST_IS_NOTHROW_MOVE_ASSIGN(T)][Should evaluate to true T has a non-throwing move assign operator.]] |
| 63 | [[BOOST_IS_NOTHROW_MOVE_CONSTRUCT(T)][Should evaluate to true T has a non-throwing move constructor.]] |
| 64 | [[BOOST_IS_POLYMORPHIC(T)][Should evaluate to true if T is a polymorphic type]] |
| 65 | [[BOOST_IS_POD(T)][Should evaluate to true if T is a POD type]] |
| 66 | [[BOOST_IS_UNION(T)][Should evaluate to true if T is a union type]] |
| 67 | [[BOOST_HAS_NOTHROW_ASSIGN(T)][Should evaluate to true if `T t, u; t = u` can not throw]] |
| 68 | [[BOOST_HAS_NOTHROW_CONSTRUCTOR(T)][Should evaluate to true if `T x;` can not throw]] |
| 69 | [[BOOST_HAS_NOTHROW_COPY(T)][Should evaluate to true if `T(t)` can not throw]] |
| 70 | [[BOOST_HAS_TRIVIAL_ASSIGN(T)][Should evaluate to true if T has a trivial assignment operator (and can therefore be replaced by a call to memcpy)]] |
| 71 | [[BOOST_HAS_TRIVIAL_CONSTRUCTOR(T)][Should evaluate to true if the default constructor for T is trivial (i.e. has no effect)]] |
| 72 | [[BOOST_HAS_TRIVIAL_COPY(T)][Should evaluate to true if T has a trivial copy constructor (and can therefore be replaced by a call to memcpy)]] |
| 73 | [[BOOST_HAS_TRIVIAL_DESTRUCTOR(T)][Should evaluate to true if T has a trivial destructor (i.e. ~T() has no effect)]] |
| 74 | [[BOOST_HAS_TRIVIAL_MOVE_CONSTRUCTOR(T)][Should evaluate to true if T has a trivial move constructor (and can therefore be replaced by a call to memcpy)]] |
| 75 | [[BOOST_HAS_TRIVIAL_MOVE_ASSIGN(T)][Should evaluate to true if T has a trivial move assignment operator (and can therefore be replaced by a call to memcpy)]] |
| 76 | [[BOOST_HAS_VIRTUAL_DESTRUCTOR(T)][Should evaluate to true T has a virtual destructor]] |
| 77 | |
| 78 | |
| 79 | ] |
| 80 | |
| 81 | [endsect] |
| 82 | |