...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
template <class T> struct has_trivial_constructor : publictrue_type-or-false_type
{}; template <class T> struct has_trivial_default_constructor : publictrue_type-or-false_type
{};
Inherits: If T is a (possibly cv-qualified) type with a trivial default-constructor then inherits from true_type, otherwise inherits from false_type.
These two traits are synonyms for each other.
If a type has a trivial default-constructor then the constructor have no effect: calls to the constructor can be safely omitted. Note that using meta-programming to omit a call to a single trivial-constructor call is of no benefit whatsoever. However, if loops and/or exception handling code can also be omitted, then some benefit in terms of code size and speed can be obtained.
Compiler Compatibility: 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. In addition, in order to correctly
handle private or deleted default-constructors then C++11's deltype
is required. Currently (May 2015)
compilers more recent than Visual C++ 8, GCC-4.3, Greenhills 6.0, Intel-11.0,
and Codegear have the necessary compiler intrinsics
to ensure that this trait "just works". You may also test to see
if the necessary intrinsics
are available by checking to see if the macro BOOST_HAS_TRIVIAL_CONSTRUCTOR
is defined.
C++ Standard Reference: 12.1p6.
Header: #include
<boost/type_traits/has_trivial_constructor.hpp>
or #include <boost/type_traits.hpp>
Examples:
has_trivial_constructor<int>
inherits fromtrue_type
.
has_trivial_constructor<char*>::type
is the typetrue_type
.
has_trivial_constructor<int (*)(long)>::value
is an integral constant expression that evaluates to true.
has_trivial_constructor<MyClass>::value
is an integral constant expression that evaluates to false.
has_trivial_constructor<T>::value_type
is the typebool
.