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:has_trivial_destructor has_trivial_destructor] |
| 9 | template <class T> |
| 10 | struct has_trivial_destructor : public __tof {}; |
| 11 | |
| 12 | __inherit If T is a (possibly cv-qualified) type with a trivial destructor |
| 13 | then inherits from __true_type, otherwise inherits from __false_type. |
| 14 | |
| 15 | If a type has a trivial destructor then the destructor has no effect: |
| 16 | calls to the destructor can be safely omitted. Note that using meta-programming |
| 17 | to omit a call to a single trivial-constructor call is of no benefit whatsoever. |
| 18 | However, if loops and/or exception handling code can also be omitted, then some |
| 19 | benefit in terms of code size and speed can be obtained. |
| 20 | |
| 21 | __compat Without some (as yet unspecified) help from the compiler, |
| 22 | has_trivial_destructor will never report that a user-defined class or struct has a |
| 23 | trivial destructor; this is always safe, if possibly sub-optimal. |
| 24 | In addition, in order to correctly handle deleted or private destructors then |
| 25 | support for C++11's `decltype` is required. |
| 26 | Currently (June 2015) compilers more recent than Visual C++ 8, GCC-4.3, Greenhills 6.0, |
| 27 | Intel-11.0, and Codegear have the necessary compiler __intrinsics to ensure that this |
| 28 | trait "just works". You may also test to see if the necessary __intrinsics are available |
| 29 | by checking to see if the macro `BOOST_HAS_TRIVIAL_DESTRUCTOR` is defined. |
| 30 | |
| 31 | |
| 32 | __std_ref 12.4p3. |
| 33 | |
| 34 | __header ` #include <boost/type_traits/has_trivial_destructor.hpp>` or ` #include <boost/type_traits.hpp>` |
| 35 | |
| 36 | __examples |
| 37 | |
| 38 | [:`has_trivial_destructor<int>` inherits from `__true_type`.] |
| 39 | |
| 40 | [:`has_trivial_destructor<char*>::type` is the type `__true_type`.] |
| 41 | |
| 42 | [:`has_trivial_destructor<int (*)(long)>::value` is an integral constant |
| 43 | expression that evaluates to /true/.] |
| 44 | |
| 45 | [:`has_trivial_destructor<MyClass>::value` is an integral constant |
| 46 | expression that evaluates to /false/.] |
| 47 | |
| 48 | [:`has_trivial_destructor<T>::value_type` is the type `bool`.] |
| 49 | |
| 50 | [endsect] |
| 51 | |