2000-07-27 13:38:51 +00:00
|
|
|
|
<html>
|
|
|
|
|
|
|
|
|
|
<head>
|
|
|
|
|
<meta http-equiv="Content-Type"
|
|
|
|
|
content="text/html; charset=iso-8859-1">
|
|
|
|
|
<meta name="Template"
|
|
|
|
|
content="C:\PROGRAM FILES\MICROSOFT OFFICE\OFFICE\html.dot">
|
|
|
|
|
<meta name="GENERATOR" content="Microsoft FrontPage Express 2.0">
|
|
|
|
|
<title>Type Traits</title>
|
|
|
|
|
</head>
|
|
|
|
|
|
|
|
|
|
<body bgcolor="#FFFFFF" link="#0000FF" vlink="#800080">
|
|
|
|
|
|
|
|
|
|
<h1><img src="../../c++boost.gif" width="276" height="86">Header
|
|
|
|
|
<<a href="../../boost/detail/type_traits.hpp">boost/type_traits.hpp</a>></h1>
|
|
|
|
|
|
|
|
|
|
<p>The contents of <boost/type_traits.hpp> are declared in
|
|
|
|
|
namespace boost.</p>
|
|
|
|
|
|
|
|
|
|
<p>The file <<a href="../../boost/detail/type_traits.hpp">boost/type_traits.hpp</a>>
|
|
|
|
|
contains various template classes that describe the fundamental
|
|
|
|
|
properties of a type; each class represents a single type
|
|
|
|
|
property or a single type transformation. This documentation is
|
|
|
|
|
divided up into the following sections:</p>
|
|
|
|
|
|
|
|
|
|
<pre><a href="#fop">Fundamental type operations</a>
|
|
|
|
|
<a href="#fp">Fundamental type properties</a>
|
2000-08-02 10:58:59 +00:00
|
|
|
|
<a href="#misc">Miscellaneous</a>
|
2000-07-27 13:38:51 +00:00
|
|
|
|
<code> </code><a href="#cv">cv-Qualifiers</a>
|
|
|
|
|
<code> </code><a href="#ft">Fundamental Types</a>
|
|
|
|
|
<code> </code><a href="#ct">Compound Types</a>
|
|
|
|
|
<code> </code><a href="#ot">Object/Scalar Types</a>
|
|
|
|
|
<a href="#cs">Compiler Support Information</a>
|
|
|
|
|
<a href="#ec">Example Code</a></pre>
|
|
|
|
|
|
|
|
|
|
<h2><a name="fop"></a>Fundamental type operations</h2>
|
|
|
|
|
|
|
|
|
|
<p>Usage: "class_name<T>::type" performs
|
|
|
|
|
indicated transformation on type T.</p>
|
|
|
|
|
|
2000-08-02 10:58:59 +00:00
|
|
|
|
<table border="1" cellpadding="7" cellspacing="1" width="100%">
|
2000-07-27 13:38:51 +00:00
|
|
|
|
<tr>
|
|
|
|
|
<td valign="top" width="45%"><p align="center">Expression.</p>
|
|
|
|
|
</td>
|
|
|
|
|
<td valign="top" width="45%"><p align="center">Description.</p>
|
|
|
|
|
</td>
|
|
|
|
|
<td valign="top" width="33%"><p align="center">Compiler.</p>
|
|
|
|
|
</td>
|
|
|
|
|
</tr>
|
|
|
|
|
<tr>
|
|
|
|
|
<td valign="top" width="45%"><code>remove_volatile<T>::type</code></td>
|
|
|
|
|
<td valign="top" width="45%">Creates a type the same as T
|
|
|
|
|
but with any top level volatile qualifier removed. For
|
|
|
|
|
example "volatile int" would become "int".</td>
|
|
|
|
|
<td valign="top" width="33%"><p align="center">P</p>
|
|
|
|
|
</td>
|
|
|
|
|
</tr>
|
|
|
|
|
<tr>
|
|
|
|
|
<td valign="top" width="45%"><code>remove_const<T>::type</code></td>
|
|
|
|
|
<td valign="top" width="45%">Creates a type the same as T
|
|
|
|
|
but with any top level const qualifier removed. For
|
|
|
|
|
example "const int" would become "int".</td>
|
|
|
|
|
<td valign="top" width="33%"><p align="center">P</p>
|
|
|
|
|
</td>
|
|
|
|
|
</tr>
|
|
|
|
|
<tr>
|
|
|
|
|
<td valign="top" width="45%"><code>remove_cv<T>::type</code></td>
|
|
|
|
|
<td valign="top" width="45%">Creates a type the same as T
|
|
|
|
|
but with any top level cv-qualifiers removed. For example
|
|
|
|
|
"const int" would become "int", and
|
|
|
|
|
"volatile double" would become "double".</td>
|
|
|
|
|
<td valign="top" width="33%"><p align="center">P</p>
|
|
|
|
|
</td>
|
|
|
|
|
</tr>
|
|
|
|
|
<tr>
|
|
|
|
|
<td valign="top" width="45%"><code>remove_reference<T>::type</code></td>
|
|
|
|
|
<td valign="top" width="45%">If T is a reference type
|
|
|
|
|
then removes the reference, otherwise leaves T unchanged.
|
|
|
|
|
For example "int&" becomes "int"
|
|
|
|
|
but "int*" remains unchanged.</td>
|
|
|
|
|
<td valign="top" width="33%"><p align="center">P</p>
|
|
|
|
|
</td>
|
|
|
|
|
</tr>
|
|
|
|
|
<tr>
|
|
|
|
|
<td valign="top" width="45%"><code>add_reference<T>::type</code></td>
|
|
|
|
|
<td valign="top" width="45%">If T is a reference type
|
|
|
|
|
then leaves T unchanged, otherwise converts T to a
|
|
|
|
|
reference type. For example "int&" remains
|
|
|
|
|
unchanged, but "double" becomes "double&".</td>
|
|
|
|
|
<td valign="top" width="33%"><p align="center">P</p>
|
|
|
|
|
</td>
|
|
|
|
|
</tr>
|
|
|
|
|
<tr>
|
|
|
|
|
<td valign="top" width="45%"><code>remove_bounds<T>::type</code></td>
|
|
|
|
|
<td valign="top" width="45%">If T is an array type then
|
|
|
|
|
removes the top level array qualifier from T, otherwise
|
|
|
|
|
leaves T unchanged. For example "int[2][3]"
|
|
|
|
|
becomes "int[3]".</td>
|
|
|
|
|
<td valign="top" width="33%"><p align="center">P</p>
|
|
|
|
|
</td>
|
|
|
|
|
</tr>
|
|
|
|
|
</table>
|
|
|
|
|
|
|
|
|
|
<p> </p>
|
|
|
|
|
|
|
|
|
|
<h2><a name="fp"></a>Fundamental type properties</h2>
|
|
|
|
|
|
|
|
|
|
<p>Usage: "class_name<T>::value" is true if
|
|
|
|
|
indicated property is true, false otherwise. (Note that class_name<T>::value
|
|
|
|
|
is always defined as a compile time constant).</p>
|
|
|
|
|
|
2000-08-02 10:58:59 +00:00
|
|
|
|
<h3><a name="misc"></a>Miscellaneous</h3>
|
|
|
|
|
|
|
|
|
|
<table border="1" cellspacing="1" width="100%">
|
|
|
|
|
<tr>
|
|
|
|
|
<td width="37%"><p align="center">Expression</p>
|
|
|
|
|
</td>
|
|
|
|
|
<td width="36%"><p align="center">Description</p>
|
|
|
|
|
</td>
|
|
|
|
|
<td width="27%"><p align="center">Compiler</p>
|
|
|
|
|
</td>
|
|
|
|
|
</tr>
|
|
|
|
|
<tr>
|
|
|
|
|
<td width="37%"><div align="center"><center><pre><code>is_same<T,U>::value</code></pre>
|
|
|
|
|
</center></div></td>
|
|
|
|
|
<td width="36%"><p align="center">True if T and U are the
|
|
|
|
|
same type.</p>
|
|
|
|
|
</td>
|
|
|
|
|
<td width="27%"><p align="center">P</p>
|
|
|
|
|
</td>
|
|
|
|
|
</tr>
|
|
|
|
|
<tr>
|
|
|
|
|
<td width="37%"><div align="center"><center><pre>is_convertible<T,U>::value</pre>
|
|
|
|
|
</center></div></td>
|
|
|
|
|
<td width="36%"><p align="center">True if type T is
|
|
|
|
|
convertible to type U.</p>
|
|
|
|
|
</td>
|
|
|
|
|
<td width="27%"> </td>
|
|
|
|
|
</tr>
|
|
|
|
|
<tr>
|
|
|
|
|
<td width="37%"><div align="center"><center><pre>alignment_of<T>::value</pre>
|
|
|
|
|
</center></div></td>
|
|
|
|
|
<td width="36%"><p align="center">An integral value
|
|
|
|
|
representing the minimum alignment requirements of type T
|
|
|
|
|
(strictly speaking defines a multiple of the type's
|
|
|
|
|
alignment requirement; for all compilers tested so far
|
|
|
|
|
however it does return the actual alignment).</p>
|
|
|
|
|
</td>
|
|
|
|
|
<td width="27%"> </td>
|
|
|
|
|
</tr>
|
|
|
|
|
</table>
|
|
|
|
|
|
|
|
|
|
<p> </p>
|
|
|
|
|
|
2000-07-27 13:38:51 +00:00
|
|
|
|
<h3><a name="cv"></a>cv-Qualifiers</h3>
|
|
|
|
|
|
|
|
|
|
<p>The following classes determine what cv-qualifiers are present
|
|
|
|
|
on a type (see 3.93).</p>
|
|
|
|
|
|
2000-08-02 10:58:59 +00:00
|
|
|
|
<table border="1" cellpadding="7" cellspacing="1" width="100%">
|
2000-07-27 13:38:51 +00:00
|
|
|
|
<tr>
|
2000-08-02 10:58:59 +00:00
|
|
|
|
<td valign="top" width="37%"><p align="center">Expression.</p>
|
2000-07-27 13:38:51 +00:00
|
|
|
|
</td>
|
2000-08-02 10:58:59 +00:00
|
|
|
|
<td valign="top" width="37%"><p align="center">Description.</p>
|
2000-07-27 13:38:51 +00:00
|
|
|
|
</td>
|
2000-08-02 10:58:59 +00:00
|
|
|
|
<td valign="top" width="27%"><p align="center">Compiler.</p>
|
2000-07-27 13:38:51 +00:00
|
|
|
|
</td>
|
|
|
|
|
</tr>
|
|
|
|
|
<tr>
|
2000-08-02 10:58:59 +00:00
|
|
|
|
<td valign="top" width="37%"><code>is_const<T>::value</code></td>
|
|
|
|
|
<td valign="top" width="37%">True if type T is top-level
|
2000-07-27 13:38:51 +00:00
|
|
|
|
const qualified.</td>
|
2000-08-02 10:58:59 +00:00
|
|
|
|
<td valign="top" width="27%"><p align="center">P</p>
|
2000-07-27 13:38:51 +00:00
|
|
|
|
</td>
|
|
|
|
|
</tr>
|
|
|
|
|
<tr>
|
2000-08-02 10:58:59 +00:00
|
|
|
|
<td valign="top" width="37%"><code>is_volatile<T>::value</code></td>
|
|
|
|
|
<td valign="top" width="37%">True if type T is top-level
|
2000-07-27 13:38:51 +00:00
|
|
|
|
volatile qualified.</td>
|
2000-08-02 10:58:59 +00:00
|
|
|
|
<td valign="top" width="27%"><p align="center">P</p>
|
2000-07-27 13:38:51 +00:00
|
|
|
|
</td>
|
|
|
|
|
</tr>
|
|
|
|
|
</table>
|
|
|
|
|
|
|
|
|
|
<p> </p>
|
|
|
|
|
|
|
|
|
|
<h3><a name="ft"></a>Fundamental Types</h3>
|
|
|
|
|
|
|
|
|
|
<p>The following will only ever be true for cv-unqualified types;
|
|
|
|
|
these are closely based on the section 3.9 of the C++ Standard.</p>
|
|
|
|
|
|
2000-08-02 10:58:59 +00:00
|
|
|
|
<table border="1" cellpadding="7" cellspacing="1" width="100%">
|
2000-07-27 13:38:51 +00:00
|
|
|
|
<tr>
|
|
|
|
|
<td valign="top" width="45%"><p align="center">Expression.</p>
|
|
|
|
|
</td>
|
|
|
|
|
<td valign="top" width="45%"><p align="center">Description.</p>
|
|
|
|
|
</td>
|
|
|
|
|
<td valign="top" width="33%"><p align="center">Compiler.</p>
|
|
|
|
|
</td>
|
|
|
|
|
</tr>
|
|
|
|
|
<tr>
|
|
|
|
|
<td valign="top" width="45%"><code>is_void<T>::value</code></td>
|
|
|
|
|
<td valign="top" width="45%">True only if T is void.</td>
|
|
|
|
|
<td valign="top" width="33%"> </td>
|
|
|
|
|
</tr>
|
|
|
|
|
<tr>
|
|
|
|
|
<td valign="top" width="45%"><code>is_standard_unsigned_integral<T>::value</code></td>
|
|
|
|
|
<td valign="top" width="45%">True only if T is one of the
|
|
|
|
|
standard unsigned integral types (3.9.1 p3) - unsigned
|
|
|
|
|
char, unsigned short, unsigned int, and unsigned long.</td>
|
|
|
|
|
<td valign="top" width="33%"> </td>
|
|
|
|
|
</tr>
|
|
|
|
|
<tr>
|
|
|
|
|
<td valign="top" width="45%"><code>is_standard_signed_integral<T>::value</code></td>
|
|
|
|
|
<td valign="top" width="45%">True only if T is one of the
|
|
|
|
|
standard signed integral types (3.9.1 p2) - signed char,
|
|
|
|
|
short, int, and long.</td>
|
|
|
|
|
<td valign="top" width="33%"> </td>
|
|
|
|
|
</tr>
|
|
|
|
|
<tr>
|
|
|
|
|
<td valign="top" width="45%"><code>is_standard_integral<T>::value</code></td>
|
|
|
|
|
<td valign="top" width="45%">True if T is a standard
|
|
|
|
|
integral type(3.9.1 p7) - T is either char, wchar_t, bool
|
|
|
|
|
or either is_standard_signed_integral<T>::value or
|
|
|
|
|
is_standard_integral<T>::value is true.</td>
|
|
|
|
|
<td valign="top" width="33%"> </td>
|
|
|
|
|
</tr>
|
|
|
|
|
<tr>
|
|
|
|
|
<td valign="top" width="45%"><code>is_standard_float<T>::value</code></td>
|
|
|
|
|
<td valign="top" width="45%">True if T is one of the
|
|
|
|
|
standard floating point types(3.9.1 p8) - float, double
|
|
|
|
|
or long double.</td>
|
|
|
|
|
<td valign="top" width="33%"> </td>
|
|
|
|
|
</tr>
|
|
|
|
|
<tr>
|
|
|
|
|
<td valign="top" width="45%"><code>is_standard_arithmetic<T>::value</code></td>
|
|
|
|
|
<td valign="top" width="45%">True if T is a standard
|
|
|
|
|
arithmetic type(3.9.1 p8) - implies is_standard_integral
|
|
|
|
|
or is_standard_float is true.</td>
|
|
|
|
|
<td valign="top" width="33%"> </td>
|
|
|
|
|
</tr>
|
|
|
|
|
<tr>
|
|
|
|
|
<td valign="top" width="45%"><code>is_standard_fundamental<T>::value</code></td>
|
|
|
|
|
<td valign="top" width="45%">True if T is a standard
|
|
|
|
|
arithmetic type or if T is void.</td>
|
|
|
|
|
<td valign="top" width="33%"> </td>
|
|
|
|
|
</tr>
|
|
|
|
|
<tr>
|
|
|
|
|
<td valign="top" width="45%"><code>is_extension_unsigned_integral<T>::value</code></td>
|
|
|
|
|
<td valign="top" width="45%">True for compiler specific
|
|
|
|
|
unsigned integral types.</td>
|
|
|
|
|
<td valign="top" width="33%"> </td>
|
|
|
|
|
</tr>
|
|
|
|
|
<tr>
|
|
|
|
|
<td valign="top" width="45%"><code>is_extension_signed_integral<T>>:value</code></td>
|
|
|
|
|
<td valign="top" width="45%">True for compiler specific
|
|
|
|
|
signed integral types.</td>
|
|
|
|
|
<td valign="top" width="33%"> </td>
|
|
|
|
|
</tr>
|
|
|
|
|
<tr>
|
|
|
|
|
<td valign="top" width="45%"><code>is_extension_integral<T>::value</code></td>
|
|
|
|
|
<td valign="top" width="45%">True if either is_extension_unsigned_integral<T>::value
|
|
|
|
|
or is_extension_signed_integral<T>::value is true.</td>
|
|
|
|
|
<td valign="top" width="33%"> </td>
|
|
|
|
|
</tr>
|
|
|
|
|
<tr>
|
|
|
|
|
<td valign="top" width="45%"><code>is_extension_float<T>::value</code></td>
|
|
|
|
|
<td valign="top" width="45%">True for compiler specific
|
|
|
|
|
floating point types.</td>
|
|
|
|
|
<td valign="top" width="33%"> </td>
|
|
|
|
|
</tr>
|
|
|
|
|
<tr>
|
|
|
|
|
<td valign="top" width="45%"><code>is_extension_arithmetic<T>::value</code></td>
|
|
|
|
|
<td valign="top" width="45%">True if either is_extension_integral<T>::value
|
|
|
|
|
or is_extension_float<T>::value are true.</td>
|
|
|
|
|
<td valign="top" width="33%"> </td>
|
|
|
|
|
</tr>
|
|
|
|
|
<tr>
|
|
|
|
|
<td valign="top" width="45%"><code> is_extension_fundamental<T>::value</code></td>
|
|
|
|
|
<td valign="top" width="45%">True if either is_extension_arithmetic<T>::value
|
|
|
|
|
or is_void<T>::value are true.</td>
|
|
|
|
|
<td valign="top" width="33%"> </td>
|
|
|
|
|
</tr>
|
|
|
|
|
<tr>
|
|
|
|
|
<td valign="top" width="45%"><code> is_unsigned_integral<T>::value</code></td>
|
|
|
|
|
<td valign="top" width="45%">True if either is_standard_unsigned_integral<T>::value
|
|
|
|
|
or is_extention_unsigned_integral<T>::value are
|
|
|
|
|
true.</td>
|
|
|
|
|
<td valign="top" width="33%"> </td>
|
|
|
|
|
</tr>
|
|
|
|
|
<tr>
|
|
|
|
|
<td valign="top" width="45%"><code>is_signed_integral<T>::value</code></td>
|
|
|
|
|
<td valign="top" width="45%">True if either is_standard_signed_integral<T>::value
|
|
|
|
|
or is_extention_signed_integral<T>>::value are
|
|
|
|
|
true.</td>
|
|
|
|
|
<td valign="top" width="33%"> </td>
|
|
|
|
|
</tr>
|
|
|
|
|
<tr>
|
|
|
|
|
<td valign="top" width="45%"><code>is_integral<T>::value</code></td>
|
|
|
|
|
<td valign="top" width="45%">True if either is_standard_integral<T>::value
|
|
|
|
|
or is_extention_integral<T>::value are true.</td>
|
|
|
|
|
<td valign="top" width="33%"> </td>
|
|
|
|
|
</tr>
|
|
|
|
|
<tr>
|
|
|
|
|
<td valign="top" width="45%"><code>is_float<T>::value</code></td>
|
|
|
|
|
<td valign="top" width="45%">True if either is_standard_float<T>::value
|
|
|
|
|
or is_extention_float<T>::value are true.</td>
|
|
|
|
|
<td valign="top" width="33%"> </td>
|
|
|
|
|
</tr>
|
|
|
|
|
<tr>
|
|
|
|
|
<td valign="top" width="45%"><code>is_arithmetic<T>::value</code></td>
|
|
|
|
|
<td valign="top" width="45%">True if either is_integral<T>::value
|
|
|
|
|
or is_float<T>::value are true.</td>
|
|
|
|
|
<td valign="top" width="33%"> </td>
|
|
|
|
|
</tr>
|
|
|
|
|
<tr>
|
|
|
|
|
<td valign="top" width="45%"><code>is_fundamental<T>::value</code></td>
|
|
|
|
|
<td valign="top" width="45%">True if either is_arithmetic<T>::value
|
|
|
|
|
or is_void<T>::value are true.</td>
|
|
|
|
|
<td valign="top" width="33%"> </td>
|
|
|
|
|
</tr>
|
|
|
|
|
</table>
|
|
|
|
|
|
|
|
|
|
<p> </p>
|
|
|
|
|
|
|
|
|
|
<h3><a name="ct"></a>Compound Types</h3>
|
|
|
|
|
|
|
|
|
|
<p>The following will only ever be true for cv-unqualified types,
|
|
|
|
|
as defined by the Standard. </p>
|
|
|
|
|
|
2000-08-02 10:58:59 +00:00
|
|
|
|
<table border="1" cellpadding="7" cellspacing="1" width="100%">
|
2000-07-27 13:38:51 +00:00
|
|
|
|
<tr>
|
|
|
|
|
<td valign="top" width="45%"><p align="center">Expression</p>
|
|
|
|
|
</td>
|
|
|
|
|
<td valign="top" width="45%"><p align="center">Description</p>
|
|
|
|
|
</td>
|
|
|
|
|
<td valign="top" width="33%"><p align="center">Compiler</p>
|
|
|
|
|
</td>
|
|
|
|
|
</tr>
|
|
|
|
|
<tr>
|
|
|
|
|
<td valign="top" width="45%"><code>is_array<T>::value</code></td>
|
|
|
|
|
<td valign="top" width="45%">True if T is an array type.</td>
|
|
|
|
|
<td valign="top" width="33%"><p align="center">P</p>
|
|
|
|
|
</td>
|
|
|
|
|
</tr>
|
|
|
|
|
<tr>
|
|
|
|
|
<td valign="top" width="45%"><code>is_pointer<T>::value</code></td>
|
|
|
|
|
<td valign="top" width="45%">True if T is a regular
|
|
|
|
|
pointer type - including function pointers - but
|
|
|
|
|
excluding pointers to member functions (3.9.2 p1 and 8.3.1).</td>
|
|
|
|
|
<td valign="top" width="33%"><p align="center">P</p>
|
|
|
|
|
</td>
|
|
|
|
|
</tr>
|
|
|
|
|
<tr>
|
|
|
|
|
<td valign="top" width="45%"><code>is_member_pointer<T>::value</code></td>
|
|
|
|
|
<td valign="top" width="45%">True if T is a pointer to a
|
|
|
|
|
non-static class member (3.9.2 p1 and 8.3.1).</td>
|
|
|
|
|
<td valign="top" width="33%"><p align="center">P</p>
|
|
|
|
|
</td>
|
|
|
|
|
</tr>
|
|
|
|
|
<tr>
|
|
|
|
|
<td valign="top" width="45%"><code>is_reference<T>::value</code></td>
|
|
|
|
|
<td valign="top" width="45%">True if T is a reference
|
|
|
|
|
type (3.9.2 p1 and 8.3.2).</td>
|
|
|
|
|
<td valign="top" width="33%"><p align="center">P</p>
|
|
|
|
|
</td>
|
|
|
|
|
</tr>
|
|
|
|
|
<tr>
|
|
|
|
|
<td valign="top" width="45%"><code>is_class<T>::value</code></td>
|
|
|
|
|
<td valign="top" width="45%">True if T is a class or
|
|
|
|
|
struct type.</td>
|
|
|
|
|
<td valign="top" width="33%"><p align="center">PD</p>
|
|
|
|
|
</td>
|
|
|
|
|
</tr>
|
|
|
|
|
<tr>
|
|
|
|
|
<td valign="top" width="45%"><code>is_union<T>::value</code></td>
|
|
|
|
|
<td valign="top" width="45%">True if T is a union type.</td>
|
|
|
|
|
<td valign="top" width="33%"><p align="center">C</p>
|
|
|
|
|
</td>
|
|
|
|
|
</tr>
|
|
|
|
|
<tr>
|
|
|
|
|
<td valign="top" width="45%"><code>is_enum<T>::value</code></td>
|
|
|
|
|
<td valign="top" width="45%">True if T is an enumerator
|
|
|
|
|
type.</td>
|
|
|
|
|
<td valign="top" width="33%"><p align="center">C</p>
|
|
|
|
|
</td>
|
|
|
|
|
</tr>
|
|
|
|
|
<tr>
|
|
|
|
|
<td valign="top" width="45%"><code>is_compound<T>::value</code></td>
|
|
|
|
|
<td valign="top" width="45%">True if T is any of the
|
|
|
|
|
above compound types.</td>
|
|
|
|
|
<td valign="top" width="33%"><p align="center">PD</p>
|
|
|
|
|
</td>
|
|
|
|
|
</tr>
|
|
|
|
|
</table>
|
|
|
|
|
|
|
|
|
|
<p> </p>
|
|
|
|
|
|
|
|
|
|
<h3><a name="ot"></a>Object/Scalar Types</h3>
|
|
|
|
|
|
|
|
|
|
<p>The following ignore any top level cv-qualifiers: if <code>class_name<T>::value</code>
|
|
|
|
|
is true then <code>class_name<cv-qualified-T>::value</code>
|
|
|
|
|
will also be true.</p>
|
|
|
|
|
|
2000-08-02 10:58:59 +00:00
|
|
|
|
<table border="1" cellpadding="7" cellspacing="1" width="100%">
|
2000-07-27 13:38:51 +00:00
|
|
|
|
<tr>
|
|
|
|
|
<td valign="top" width="45%"><p align="center">Expression</p>
|
|
|
|
|
</td>
|
|
|
|
|
<td valign="top" width="45%"><p align="center">Description</p>
|
|
|
|
|
</td>
|
|
|
|
|
<td valign="top" width="33%"><p align="center">Compiler</p>
|
|
|
|
|
</td>
|
|
|
|
|
</tr>
|
|
|
|
|
<tr>
|
|
|
|
|
<td valign="top" width="45%"><code>is_object<T>::value</code></td>
|
|
|
|
|
<td valign="top" width="45%">True if T is not a reference
|
|
|
|
|
type, or a (possibly cv-qualified) void type.</td>
|
|
|
|
|
<td valign="top" width="33%"><p align="center">P</p>
|
|
|
|
|
</td>
|
|
|
|
|
</tr>
|
|
|
|
|
<tr>
|
|
|
|
|
<td valign="top" width="45%"><code>is_standard_scalar<T>::value</code></td>
|
|
|
|
|
<td valign="top" width="45%">True if T is a standard
|
|
|
|
|
arithmetic type, an enumerated type, a pointer or a
|
|
|
|
|
member pointer.</td>
|
|
|
|
|
<td valign="top" width="33%"><p align="center">PD</p>
|
|
|
|
|
</td>
|
|
|
|
|
</tr>
|
|
|
|
|
<tr>
|
|
|
|
|
<td valign="top" width="45%"><code>is_extension_scalar<T>::value</code></td>
|
|
|
|
|
<td valign="top" width="45%">True if T is an extentions
|
|
|
|
|
arithmetic type, an enumerated type, a pointer or a
|
|
|
|
|
member pointer.</td>
|
|
|
|
|
<td valign="top" width="33%"><p align="center">PD</p>
|
|
|
|
|
</td>
|
|
|
|
|
</tr>
|
|
|
|
|
<tr>
|
|
|
|
|
<td valign="top" width="45%"><code>is_scalar<T>::value</code></td>
|
|
|
|
|
<td valign="top" width="45%">True if T is an arithmetic
|
|
|
|
|
type, an enumerated type, a pointer or a member pointer.</td>
|
|
|
|
|
<td valign="top" width="33%"><p align="center">PD</p>
|
|
|
|
|
</td>
|
|
|
|
|
</tr>
|
|
|
|
|
<tr>
|
|
|
|
|
<td valign="top" width="45%"><code>is_POD<T>::value</code></td>
|
|
|
|
|
<td valign="top" width="45%">True if T is a "Plain
|
|
|
|
|
Old Data" type (see 3.9 p2&p3). Note that
|
|
|
|
|
although this requires compiler support to be correct in
|
|
|
|
|
all cases, if T is a scalar or an array of scalars then
|
|
|
|
|
we can correctly define T as a POD.</td>
|
|
|
|
|
<td valign="top" width="33%"><p align="center">PC</p>
|
|
|
|
|
</td>
|
|
|
|
|
</tr>
|
|
|
|
|
<tr>
|
|
|
|
|
<td valign="top" width="45%"><code>is_empty<T>::value</code></td>
|
|
|
|
|
<td valign="top" width="45%">True if T is an empty struct
|
|
|
|
|
or class. If the compiler implements the "zero sized
|
|
|
|
|
empty base classes" optimisation, then is_empty will
|
|
|
|
|
correctly guess whether T is empty. Relies upon is_class
|
2000-08-02 10:58:59 +00:00
|
|
|
|
to determine whether T is a class type. Screens out enum
|
|
|
|
|
types by using is_convertible<T,int>, this means
|
|
|
|
|
that empty classes that overload operator int(), will not
|
|
|
|
|
be classified as empty.</td>
|
2000-07-27 13:38:51 +00:00
|
|
|
|
<td valign="top" width="33%"><p align="center">PCD</p>
|
|
|
|
|
</td>
|
|
|
|
|
</tr>
|
|
|
|
|
<tr>
|
|
|
|
|
<td valign="top" width="45%"><code>has_trivial_constructor<T>::value</code></td>
|
|
|
|
|
<td valign="top" width="45%">True if T has a trivial
|
|
|
|
|
default constructor - that is T() is equivalent to memset.</td>
|
|
|
|
|
<td valign="top" width="33%"><p align="center">PC</p>
|
|
|
|
|
</td>
|
|
|
|
|
</tr>
|
|
|
|
|
<tr>
|
|
|
|
|
<td valign="top" width="45%"><code>has_trivial_copy<T>::value</code></td>
|
|
|
|
|
<td valign="top" width="45%">True if T has a trivial copy
|
|
|
|
|
constructor - that is T(const T&) is equivalent to
|
|
|
|
|
memcpy.</td>
|
|
|
|
|
<td valign="top" width="33%"><p align="center">PC</p>
|
|
|
|
|
</td>
|
|
|
|
|
</tr>
|
|
|
|
|
<tr>
|
|
|
|
|
<td valign="top" width="45%"><code>has_trivial_assign<T>::value</code></td>
|
|
|
|
|
<td valign="top" width="45%">True if T has a trivial
|
|
|
|
|
assignment operator - that is if T::operator=(const T&)
|
|
|
|
|
is equivalent to memcpy.</td>
|
|
|
|
|
<td valign="top" width="33%"><p align="center">PC</p>
|
|
|
|
|
</td>
|
|
|
|
|
</tr>
|
|
|
|
|
<tr>
|
|
|
|
|
<td valign="top" width="45%"><code>has_trivial_destructor<T>::value</code></td>
|
|
|
|
|
<td valign="top" width="45%">True if T has a trivial
|
|
|
|
|
destructor - that is if T::~T() has no effect.</td>
|
|
|
|
|
<td valign="top" width="33%"><p align="center">PC</p>
|
|
|
|
|
</td>
|
|
|
|
|
</tr>
|
|
|
|
|
</table>
|
|
|
|
|
|
|
|
|
|
<p> </p>
|
|
|
|
|
|
|
|
|
|
<h2><a name="cs"></a>Compiler Support Information</h2>
|
|
|
|
|
|
|
|
|
|
<p>The legends used in the tables above have the following
|
|
|
|
|
meanings:</p>
|
|
|
|
|
|
|
|
|
|
<table border="0" cellpadding="7" cellspacing="0" width="480">
|
|
|
|
|
<tr>
|
|
|
|
|
<td valign="top" width="50%"><p align="center">P</p>
|
|
|
|
|
</td>
|
|
|
|
|
<td valign="top" width="90%">Denotes that the class
|
|
|
|
|
requires support for partial specialisation of class
|
|
|
|
|
templates to work correctly.</td>
|
|
|
|
|
</tr>
|
|
|
|
|
<tr>
|
|
|
|
|
<td valign="top" width="50%"><p align="center">C</p>
|
|
|
|
|
</td>
|
|
|
|
|
<td valign="top" width="90%">Denotes that direct compiler
|
|
|
|
|
support for that traits class is required.</td>
|
|
|
|
|
</tr>
|
|
|
|
|
<tr>
|
|
|
|
|
<td valign="top" width="50%"><p align="center">D</p>
|
|
|
|
|
</td>
|
|
|
|
|
<td valign="top" width="90%">Denotes that the traits
|
|
|
|
|
class is dependent upon a class that requires direct
|
|
|
|
|
compiler support.</td>
|
|
|
|
|
</tr>
|
|
|
|
|
</table>
|
|
|
|
|
|
|
|
|
|
<p> </p>
|
|
|
|
|
|
|
|
|
|
<p>For those classes that are marked with a D or C, if compiler
|
|
|
|
|
support is not provided, this type trait may return "false"
|
|
|
|
|
when the correct value is actually "true". The single
|
|
|
|
|
exception to this rule is "is_class", which attempts to
|
|
|
|
|
guess whether or not T is really a class, and may return "true"
|
|
|
|
|
when the correct value is actually "false". This can
|
|
|
|
|
happen if: T is a union, T is an enum, or T is a compiler-supplied
|
|
|
|
|
scalar type that is not specialised for in these type traits.</p>
|
|
|
|
|
|
|
|
|
|
<p><i>If there is no compiler support</i>, to ensure that these
|
|
|
|
|
traits <i>always</i> return the correct values, specialise 'is_enum'
|
|
|
|
|
for each user-defined enumeration type, 'is_union' for each user-defined
|
|
|
|
|
union type, 'is_empty' for each user-defined empty composite type,
|
|
|
|
|
and 'is_POD' for each user-defined POD type. The 'has_*' traits
|
|
|
|
|
should also be specialized if the user-defined type has those
|
|
|
|
|
traits and is <i>not</i> a POD.</p>
|
|
|
|
|
|
|
|
|
|
<p>The following rules are automatically enforced:</p>
|
|
|
|
|
|
|
|
|
|
<p>is_enum implies is_POD</p>
|
|
|
|
|
|
|
|
|
|
<p>is_POD implies has_*</p>
|
|
|
|
|
|
|
|
|
|
<p>This means, for example, if you have an empty POD-struct, just
|
|
|
|
|
specialize is_empty and is_POD, which will cause all the has_* to
|
|
|
|
|
also return true.</p>
|
|
|
|
|
|
|
|
|
|
<h2><a name="ec"></a>Example code</h2>
|
|
|
|
|
|
|
|
|
|
<p>Type-traits comes with two sample programs: <a
|
|
|
|
|
href="type_traits_test.cpp">type_traits_test.cpp</a> tests the
|
|
|
|
|
type traits classes - mostly this is a test of your compiler's
|
|
|
|
|
support for the concepts used in the type traits implementation,
|
|
|
|
|
while <a href="algo_opt_examples.cpp">algo_opt_examples.cpp</a>
|
|
|
|
|
uses the type traits classes to "optimise" some
|
|
|
|
|
familiar standard library algorithms.</p>
|
|
|
|
|
|
|
|
|
|
<p>There are four algorithm examples in algo_opt_examples.cpp:</p>
|
|
|
|
|
|
|
|
|
|
<table border="0" cellpadding="7" cellspacing="0" width="638">
|
|
|
|
|
<tr>
|
|
|
|
|
<td valign="top" width="50%"><pre>opt::copy</pre>
|
|
|
|
|
</td>
|
|
|
|
|
<td valign="top" width="50%">If the copy operation can be
|
|
|
|
|
performed using memcpy then does so, otherwise uses a
|
|
|
|
|
regular element by element copy (<i>c.f.</i> std::copy).</td>
|
|
|
|
|
</tr>
|
|
|
|
|
<tr>
|
|
|
|
|
<td valign="top" width="50%"><pre>opt::fill</pre>
|
|
|
|
|
</td>
|
|
|
|
|
<td valign="top" width="50%">If the fill operation can be
|
|
|
|
|
performed by memset, then does so, otherwise uses a
|
|
|
|
|
regular element by element assign. Also uses call_traits
|
|
|
|
|
to optimise how the parameters can be passed (<i>c.f.</i>
|
|
|
|
|
std::fill).</td>
|
|
|
|
|
</tr>
|
|
|
|
|
<tr>
|
|
|
|
|
<td valign="top" width="50%"><pre>opt::destroy_array</pre>
|
|
|
|
|
</td>
|
|
|
|
|
<td valign="top" width="50%">If the type in the array has
|
|
|
|
|
a trivial destructor then does nothing, otherwise calls
|
|
|
|
|
destructors for all elements in the array - this
|
|
|
|
|
algorithm is the reverse of std::uninitialized_copy / std::uninitialized_fill.</td>
|
|
|
|
|
</tr>
|
|
|
|
|
<tr>
|
|
|
|
|
<td valign="top" width="50%"><pre>opt::iter_swap</pre>
|
|
|
|
|
</td>
|
|
|
|
|
<td valign="top" width="50%">Determines whether the
|
|
|
|
|
iterator is a proxy-iterator: if it is then does a "slow
|
|
|
|
|
and safe" swap, otherwise calls std::swap on the
|
|
|
|
|
assumption that std::swap may be specialised for the
|
|
|
|
|
iterated type.</td>
|
|
|
|
|
</tr>
|
|
|
|
|
</table>
|
|
|
|
|
|
|
|
|
|
<p> </p>
|
|
|
|
|
|
|
|
|
|
<hr>
|
|
|
|
|
|
|
|
|
|
<p>Revised 08<sup>th</sup> March 2000</p>
|
|
|
|
|
|
|
|
|
|
<p><EFBFBD> Copyright boost.org 2000. Permission to copy, use, modify,
|
|
|
|
|
sell and distribute this document is granted provided this
|
|
|
|
|
copyright notice appears in all copies. This document is provided
|
|
|
|
|
"as is" without express or implied warranty, and with
|
|
|
|
|
no claim as to its suitability for any purpose.</p>
|
|
|
|
|
|
|
|
|
|
<p>Based on contributions by Steve Cleary, Beman Dawes, Howard
|
|
|
|
|
Hinnant and John Maddock.</p>
|
|
|
|
|
|
|
|
|
|
<p>Maintained by <a href="mailto:John_Maddock@compuserve.com">John
|
|
|
|
|
Maddock</a>, the latest version of this file can be found at <a
|
2000-08-02 10:58:59 +00:00
|
|
|
|
href="http://www.boost.org/">www.boost.org</a>, and the boost
|
2000-07-27 13:38:51 +00:00
|
|
|
|
discussion list at <a href="http://www.egroups.com/list/boost">www.egroups.com/list/boost</a>.</p>
|
|
|
|
|
</body>
|
|
|
|
|
</html>
|