📄 type_traits.qbk
字号:
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 <boost/type_traits/has_nothrow_copy.hpp>` or ` #include <boost/type_traits.hpp>`
[endsect]
[section:has_trivial_assign has_trivial_assign]
template <class T>
struct has_trivial_assign : public __tof {};
__inherit If T is a (possibly cv-qualified) type with a trivial assignment-operator
then inherits from __true_type, otherwise inherits from __false_type.
If a type has a trivial assignment-operator then the operator has the same effect
as copying the bits of one object to the other:
calls to the operator can be safely replaced with a call to `memcpy`.
__compat If the compiler does not support partial-specialization of class
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
(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.
__header ` #include <boost/type_traits/has_trivial_assign.hpp>` or ` #include <boost/type_traits.hpp>`
__examples
[:`has_trivial_assign<int>` inherits from `__true_type`.]
[:`has_trivial_assign<char*>::type` is the type `__true_type`.]
[:`has_trivial_assign<int (*)(long)>::value` is an integral constant
expression that evaluates to /true/.]
[:`has_trivial_assign<MyClass>::value` is an integral constant
expression that evaluates to /false/.]
[:`has_trivial_assign<T>::value_type` is the type `bool`.]
[endsect]
[section:has_trivial_constructor has_trivial_constructor]
template <class T>
struct has_trivial_constructor : public __tof {};
__inherit If T is a (possibly cv-qualified) type with a trivial default-constructor
then inherits from __true_type, otherwise inherits from __false_type.
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.
__compat If the compiler does not support partial-specialization of class
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
(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.
__header ` #include <boost/type_traits/has_trivial_constructor.hpp>` or ` #include <boost/type_traits.hpp>`
__examples
[:`has_trivial_constructor<int>` inherits from `__true_type`.]
[:`has_trivial_constructor<char*>::type` is the type `__true_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 type `bool`.]
[endsect]
[section:has_trivial_copy has_trivial_copy]
template <class T>
struct has_trivial_copy : public __tof {};
__inherit If T is a (possibly cv-qualified) type with a trivial copy-constructor
then inherits from __true_type, otherwise inherits from __false_type.
If a type has a trivial copy-constructor then the constructor has the same effect
as copying the bits of one object to the other:
calls to the constructor can be safely replaced with a call to `memcpy`.
__compat If the compiler does not support partial-specialization of class
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
(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.
__header ` #include <boost/type_traits/has_trivial_copy.hpp>` or ` #include <boost/type_traits.hpp>`
__examples
[:`has_trivial_copy<int>` inherits from `__true_type`.]
[:`has_trivial_copy<char*>::type` is the type `__true_type`.]
[:`has_trivial_copy<int (*)(long)>::value` is an integral constant
expression that evaluates to /true/.]
[:`has_trivial_copy<MyClass>::value` is an integral constant
expression that evaluates to /false/.]
[:`has_trivial_copy<T>::value_type` is the type `bool`.]
[endsect]
[section:has_trivial_destructor has_trivial_destructor]
template <class T>
struct has_trivial_destructor : public __tof {};
__inherit If T is a (possibly cv-qualified) type with a trivial destructor
then inherits from __true_type, otherwise inherits from __false_type.
If a type has a trivial destructor then the destructor has no effect:
calls to the destructor 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.
__compat If the compiler does not support partial-specialization of class
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
(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.
__header ` #include <boost/type_traits/has_trivial_destructor.hpp>` or ` #include <boost/type_traits.hpp>`
__examples
[:`has_trivial_destructor<int>` inherits from `__true_type`.]
[:`has_trivial_destructor<char*>::type` is the type `__true_type`.]
[:`has_trivial_destructor<int (*)(long)>::value` is an integral constant
expression that evaluates to /true/.]
[:`has_trivial_destructor<MyClass>::value` is an integral constant
expression that evaluates to /false/.]
[:`has_trivial_destructor<T>::value_type` is the type `bool`.]
[endsect]
[section:has_virtual_destructor has_virtual_destructor]
template <class T>
struct has_virtual_destructor : public __tof {};
__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
always inherits from __false_type, and has to be explicitly specialized for
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.
__header ` #include <boost/type_traits/has_virtual_destructor.hpp>` or ` #include <boost/type_traits.hpp>`
[endsect]
[section:integral_constant integral_constant]
template <class T, T val>
struct integral_constant
{
typedef integral_constant<T, val> type;
typedef T value_type;
static const T value = val;
};
typedef integral_constant<bool, true> true_type;
typedef integral_constant<bool, false> false_type;
Class template `integral_constant` is the common base class for all the value-based
type traits. The two typedef's `true_type` and `false_type` are provided for
convenience: most of the value traits are Boolean properties and so will inherit from
one of these.
[endsect]
[section:is_abstract is_abstract]
template <class T>
struct is_abstract : public __tof {};
__inherit If T is a (possibly cv-qualified) abstract type then inherits from
__true_type, otherwise inherits from __false_type.
__std_ref 10.3.
__header ` #include <boost/type_traits/is_abstract.hpp>` or ` #include <boost/type_traits.hpp>`
__compat The compiler must support DR337 (as of April 2005: GCC 3.4, VC++ 7.1 (and later),
Intel C++ 7 (and later), and Comeau 4.3.2).
Otherwise behaves the same as __is_polymorphic;
this is the "safe fallback position" for which polymorphic types are always
regarded as potentially abstract. The macro BOOST_NO_IS_ABSTRACT is used to
signify that the implementation is buggy, users should check for this in their
own code if the "safe fallback" is not suitable for their particular use-case.
__examples
[:Given: `class abc{ virtual ~abc() = 0; };` ]
[:`is_abstract<abc>` inherits from `__true_type`.]
[:`is_abstract<abc>::type` is the type `__true_type`.]
[:`is_abstract<abc const>::value` is an integral constant
expression that evaluates to /true/.]
[:`is_abstract<T>::value_type` is the type `bool`.]
[endsect]
[section:is_arithmetic is_arithmetic]
template <class T>
struct is_arithmetic : public __tof {};
__inherit If T is a (possibly cv-qualified) arithmetic type then inherits from
__true_type, otherwise inherits from __false_type. Arithmetic types include
integral and floating point types (see also __is_integral and __is_floating_point).
__std_ref 3.9.1p8.
__header ` #include <boost/type_traits/is_arithmetic.hpp>` or ` #include <boost/type_traits.hpp>`
__examples
[:`is_arithmetic<int>` inherits from `__true_type`.]
[:`is_arithmetic<char>::type` is the type `__true_type`.]
[:`is_arithmetic<double>::value` is an integral constant
expression that evaluates to /true/.]
[:`is_arithmetic<T>::value_type` is the type `bool`.]
[endsect]
[section:is_array is_array]
template <class T>
struct is_array : public __tof {};
__inherit If T is a (possibly cv-qualified) array type then inherits from __true_type,
otherwise inherits from __false_type.
__std_ref 3.9.2 and 8.3.4.
__header ` #include <boost/type_traits/is_array.hpp>` or ` #include <boost/type_traits.hpp>`
__compat If the compiler does not support
partial-specialization of class templates, then this template
can give the wrong result with function types.
__examples
[:`is_array<int[2]>` inherits from `__true_type`.]
[:`is_array<char[2][3]>::type` is the type `__true_type`.]
[:`is_array<double[]>::value` is an integral constant
expression that evaluates to /true/.]
[:`is_array<T>::value_type` is the type `bool`.]
[endsect]
[section:is_base_of is_base_of]
template <class Base, class Derived>
struct is_base_of : public __tof {};
__inherit If Base is base class of type Derived then inherits from __true_type,
otherwise inherits from __false_type.
This template will detect non-public base classes, and ambiguous base classes.
Note that a class is not considered to be it's own base class,
likewise, if either `Base` or `Derived` are non-class types,
then the class will always inherit from __false_type.
Types `Base` and `Derived` must not be incomplete types.
__std_ref 10.
__header ` #include <boost/type_traits/is_base_of.hpp>` or ` #include <boost/type_traits.hpp>`
__compat If the compiler does not support partial-specialization of class templates,
then this template can not be used with function types. There are some older compilers
which will produce compiler errors if `Base` is a private base class of `Derived`, or if
`Base` is an ambiguous base of `Derived`. These compilers include Borland C++, older
versions of Sun Forte C++, Digital Mars C++, and older versions of EDG based compilers.
__examples
[:Given: ` class Base{}; class Derived : public Base{};` ]
[:`is_base_of<Base, Derived>` inherits from `__true_type`.]
[:`is_base_of<Base, Derived>::type` is the type `__true_type`.]
[:`is_base_of<Base, Derived>::value` is an integral constant
expression that evaluates to /true/.]
[:`is_base_of<Base, Base>::value` is an integral constant
expression that evaluates to /false/: a class is not it's own base.]
[:`is_base_of<Derived, Base>::value` is an integral constant
expression that ev
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -