From d9ef904fa1a9da91dd1ccda56a30cbf202b2d122 Mon Sep 17 00:00:00 2001 From: John Maddock Date: Wed, 11 May 2005 14:32:21 +0000 Subject: [PATCH] Added VC++ intrinsic support. Added intrinsic-hook docs. [SVN r28824] --- doc/type_traits.qbk | 103 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 86 insertions(+), 17 deletions(-) diff --git a/doc/type_traits.qbk b/doc/type_traits.qbk index 32733ee..41b7c86 100644 --- a/doc/type_traits.qbk +++ b/doc/type_traits.qbk @@ -29,6 +29,7 @@ [def __examples [*Examples:]] [def __type [*type:]] [def __transform_workaround [link transform.broken_compiler_workarounds_ compiler workarounds]] +[def __intrinsics [link boost_typetraits.intrinsics intrinsics]] [def __is_void [link boost_typetraits.is_void is_void]] [def __is_integral [link boost_typetraits.is_integral is_integral]] @@ -753,6 +754,61 @@ as appropriate: [endsect] +[section:intrinsics Support for Compiler Intrinsics] + +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 (May 2005) MWCW 9 and Visual C++ 8 +provide the necessary intrinsics, and other compilers will no doubt follow in due +course. + +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_assign +* __has_trivial_destructor +* __has_nothrow_constructor +* __has_nothrow_copy +* __has_nothrow_assign +* __has_virtual_destructor + +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 + +The following traits classes are dependent on one or more of the above: + +* __is_class +* __is_stateless + +The hooks for compiler-intrinsic support are defined in +[@../../boost/type_traits/intrinsics.hpp boost/type_traits/intrinsics.hpp], adding support for new compilers is simply +a matter of defining one of more of the following macros: + +[table Macros for Compiler Intrinsics + [[BOOST_IS_UNION(T)][Should evaluate to true if T is a union type]] + [[BOOST_IS_POD(T)][Should evaluate to true if T is a POD type]] + [[BOOST_IS_EMPTY(T)][Should evaluate to true if T is an empty struct or union]] + [[BOOST_HAS_TRIVIAL_CONSTRUCTOR(T)][Should evaluate to true if the default constructor for T is trivial (i.e. has no effect)]] + [[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)]] + [[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)]] + [[BOOST_HAS_TRIVIAL_DESTRUCTOR(T)][Should evaluate to true if T has a trivial destructor (i.e. ~T() has no effect)]] + [[BOOST_HAS_NOTHROW_CONSTRUCTOR(T)][Should evaluate to true if `T x;` can not throw]] + [[BOOST_HAS_NOTHROW_COPY(T)][Should evaluate to true if `T(t)` can not throw]] + [[BOOST_HAS_NOTHROW_ASSIGN(T)][Should evaluate to true if `T t, u; t = u` can not throw]] + [[BOOST_HAS_VIRTUAL_DESTRUCTOR(T)][Should evaluate to true T has a virtual destructor]] +] + +[endsect] + [section:mpl MPL Interoperability] All the value based traits in this library conform to MPL's requirements @@ -1273,6 +1329,8 @@ templates, then this template can not be used with function types. Without some (as yet unspecified) help from the compiler, `has_nothrow_assign` will never report that a class or struct has a non-throwing assignment-operator; this is always safe, if possibly sub-optimal. +Currently (May 2005) only Visual C++ 8 has the necessary compiler support to ensure that this +trait "just works". __header ` #include ` or ` #include ` @@ -1292,6 +1350,8 @@ templates, then this template can not be used with function types. Without some (as yet unspecified) help from the compiler, `has_nothrow_constructor` will never report that a class or struct has a non-throwing default-constructor; this is always safe, if possibly sub-optimal. +Currently (May 2005) only Visual C++ 8 has the necessary compiler __intrinsics to ensure that this +trait "just works". __header ` #include ` or ` #include ` @@ -1311,6 +1371,8 @@ templates, then this template can not be used with function types. Without some (as yet unspecified) help from the compiler, `has_nothrow_copy` will never report that a class or struct has a non-throwing copy-constructor; this is always safe, if possibly sub-optimal. +Currently (May 2005) only Visual C++ 8 has the necessary compiler __intrinsics to ensure that this +trait "just works". __header ` #include ` or ` #include ` @@ -1333,7 +1395,7 @@ templates, then this template can not be used with function types. Without some (as yet unspecified) help from the compiler, has_trivial_assign will never report that a user-defined class or struct has a trivial constructor; this is always safe, if possibly sub-optimal. Currently -(April 2005) only MWCW has the necessary compiler-intrinsics to detect +(May 2005) only MWCW 9 and Visual C++ 8 have the necessary compiler __intrinsics to detect user-defined classes with trivial constructors. __std_ref 12.8p11. @@ -1375,7 +1437,7 @@ templates, then this template can not be used with function types. Without some (as yet unspecified) help from the compiler, has_trivial_constructor will never report that a user-defined class or struct has a trivial constructor; this is always safe, if possibly sub-optimal. Currently -(April 2005) only MWCW has the necessary compiler-intrinsics to detect +(May 2005) only MWCW 9 and Visual C++ 8 have the necessary compiler __intrinsics to detect user-defined classes with trivial constructors. __std_ref 12.1p6. @@ -1415,7 +1477,7 @@ templates, then this template can not be used with function types. Without some (as yet unspecified) help from the compiler, has_trivial_copy will never report that a user-defined class or struct has a trivial constructor; this is always safe, if possibly sub-optimal. Currently -(April 2005) only MWCW has the necessary compiler-intrinsics to detect +(May 2005) only MWCW 9 and Visual C++ 8 have the necessary compiler __intrinsics to detect user-defined classes with trivial constructors. __std_ref 12.8p6. @@ -1457,7 +1519,7 @@ templates, then this template can not be used with function types. Without some (as yet unspecified) help from the compiler, has_trivial_destructor will never report that a user-defined class or struct has a trivial destructor; this is always safe, if possibly sub-optimal. Currently -(April 2005) only MWCW has the necessary compiler-intrinsics to detect +(May 2005) only MWCW 9 and Visual C++ 8 have the necessary compiler __intrinsics to detect user-defined classes with trivial constructors. __std_ref 12.4p3. @@ -1488,10 +1550,12 @@ __inherit If T is a (possibly cv-qualified) type with a virtual destructor then inherits from __true_type, otherwise inherits from __false_type. __compat This trait is provided for completeness, since it's part of the -Technical Report on C++ Library Extensions, however, there is currently no -way to portably implement this trait, the default version provided +Technical Report on C++ Library Extensions. However, there is currently no +way to portably implement this trait. The default version provided always inherits from __false_type, and has to be explicitly specialized for -types with virtual destructors. +types with virtual destructors unless the compiler used has compiler __intrinsics +that enable the trait to do the right thing: currently (May 2005) only Visual C++ +8 has the necessary __intrinsics. __std_ref 12.4. @@ -1664,7 +1728,9 @@ __header ` #include ` or ` #include ` or ` #include ` -__compat Relies on the compiler implementing zero sized empty base classes in -order to detect empty classes. +__compat In order to correctly detect empty classes this trait relies on either: + +* the compiler implementing zero sized empty base classes, or +* the compiler providing __intrinsics to detect empty classes. Can not be used with incomplete types. @@ -2138,8 +2206,8 @@ of class templates, then this template can not be used with function types. Without some (as yet unspecified) help from the compiler, is_pod will never report that a class or struct is a POD; this is always safe, -if possibly sub-optimal. Currently (April 2005) only MWCW provides the -necessary compiler-intrinsic support. +if possibly sub-optimal. Currently (May 2005) only MWCW 9 and Visual C++ 8 have the +necessary compiler-__intrinsics. __header ` #include ` or ` #include ` @@ -2316,8 +2384,8 @@ then this template can not be used with function types. Without some (as yet unspecified) help from the compiler, is_stateless will never report that a class or struct is stateless; this is always safe, -if possibly sub-optimal. Currently (April 2005) only MWCW has the necessary -compiler intrinsics to make this template work automatically. +if possibly sub-optimal. Currently (May 2005) only MWCW 9 and Visual C++ 8 have the necessary +compiler __intrinsics to make this template work automatically. [endsect] @@ -2364,9 +2432,10 @@ __std_ref 3.9.2 and 9.5. __compat Without (some as yet unspecified) help from the compiler, we cannot distinguish between union and class types using only standard C++, as a result this type will never inherit from __true_type, unless the user explicitly -specializes the template for their user-defined union types. Now that the type traits -library is has been accepted as part of the Technical Report on C++ Library Extensions, -this situation should change as newer compiler versions are released. +specializes the template for their user-defined union types, or unless the compiler +supplies some unspecified intrinsic that implements this functionality. Currently +(May 2005) only Visual C++ 8 has the necessary compiler __intrinsics to make this +trait "just work" without user intervention. __header ` #include ` or ` #include `