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_copy has_trivial_copy] |
| 9 | |
| 10 | template <class T> |
| 11 | struct has_trivial_copy : public __tof {}; |
| 12 | |
| 13 | template <class T> |
| 14 | struct has_trivial_copy_constructor : public __tof {}; |
| 15 | |
| 16 | __inherit If T is a (possibly cv-qualified) type with a trivial copy-constructor |
| 17 | then inherits from __true_type, otherwise inherits from __false_type. |
| 18 | |
| 19 | These two traits are synonyms for each other. |
| 20 | |
| 21 | If a type has a trivial copy-constructor then the constructor has the same effect |
| 22 | as copying the bits of one object to the other: |
| 23 | calls to the constructor can be safely replaced with a call to `memcpy`. |
| 24 | |
| 25 | __compat Without some (as yet unspecified) help from the compiler, |
| 26 | has_trivial_copy will never report that a user-defined class or struct has a |
| 27 | trivial constructor; this is always safe, if possibly sub-optimal. |
| 28 | In addition, in order to correctly handle deleted or private copy-constructors |
| 29 | then C++11's `dectype` is required. |
| 30 | Currently (May 2015) compilers more recent than Visual C++ 8, GCC-4.3, Greenhills 6.0, |
| 31 | Intel-11.0, and Codegear have the necessary compiler __intrinsics to ensure that this |
| 32 | trait "just works". You may also test to see if the necessary __intrinsics are available |
| 33 | by checking to see if the macro `BOOST_HAS_TRIVIAL_COPY` is defined. |
| 34 | |
| 35 | |
| 36 | __std_ref 12.8p6. |
| 37 | |
| 38 | __header ` #include <boost/type_traits/has_trivial_copy.hpp>` or ` #include <boost/type_traits.hpp>` |
| 39 | |
| 40 | __examples |
| 41 | |
| 42 | [:`has_trivial_copy<int>` inherits from `__true_type`.] |
| 43 | |
| 44 | [:`has_trivial_copy<char*>::type` is the type `__true_type`.] |
| 45 | |
| 46 | [:`has_trivial_copy<int (*)(long)>::value` is an integral constant |
| 47 | expression that evaluates to /true/.] |
| 48 | |
| 49 | [:`has_trivial_copy<MyClass>::value` is an integral constant |
| 50 | expression that evaluates to /false/.] |
| 51 | |
| 52 | [:`has_trivial_copy<T>::value_type` is the type `bool`.] |
| 53 | |
| 54 | [endsect] |
| 55 | |