preview of updated version with is_convertible and alignment_of added.

[SVN r7667]
This commit is contained in:
John Maddock
2000-07-31 11:31:26 +00:00
parent cd4aa29cd6
commit cbc8f976c7
3 changed files with 169 additions and 23 deletions

View File

@ -25,6 +25,7 @@ divided up into the following sections:</p>
<pre><a href="#fop">Fundamental type operations</a> <pre><a href="#fop">Fundamental type operations</a>
<a href="#fp">Fundamental type properties</a> <a href="#fp">Fundamental type properties</a>
<a href="#misc">Miscellaneous</a>
<code> </code><a href="#cv">cv-Qualifiers</a> <code> </code><a href="#cv">cv-Qualifiers</a>
<code> </code><a href="#ft">Fundamental Types</a> <code> </code><a href="#ft">Fundamental Types</a>
<code> </code><a href="#ct">Compound Types</a> <code> </code><a href="#ct">Compound Types</a>
@ -37,7 +38,7 @@ divided up into the following sections:</p>
<p>Usage: &quot;class_name&lt;T&gt;::type&quot; performs <p>Usage: &quot;class_name&lt;T&gt;::type&quot; performs
indicated transformation on type T.</p> indicated transformation on type T.</p>
<table border="1" cellpadding="7" cellspacing="1" width="624"> <table border="1" cellpadding="7" cellspacing="1" width="100%">
<tr> <tr>
<td valign="top" width="45%"><p align="center">Expression.</p> <td valign="top" width="45%"><p align="center">Expression.</p>
</td> </td>
@ -108,39 +109,72 @@ indicated transformation on type T.</p>
indicated property is true, false otherwise. (Note that class_name&lt;T&gt;::value indicated property is true, false otherwise. (Note that class_name&lt;T&gt;::value
is always defined as a compile time constant).</p> is always defined as a compile time constant).</p>
<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&lt;T,U&gt;::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&lt;T,U&gt;::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%">&nbsp;</td>
</tr>
<tr>
<td width="37%"><div align="center"><center><pre>alignment_of&lt;T&gt;::value</pre>
</center></div></td>
<td width="36%"><p align="center">An integral value
representing the minimum alignment requirements of type T.</p>
</td>
<td width="27%">&nbsp;</td>
</tr>
</table>
<p>&nbsp;</p>
<h3><a name="cv"></a>cv-Qualifiers</h3> <h3><a name="cv"></a>cv-Qualifiers</h3>
<p>The following classes determine what cv-qualifiers are present <p>The following classes determine what cv-qualifiers are present
on a type (see 3.93).</p> on a type (see 3.93).</p>
<table border="1" cellpadding="7" cellspacing="1" width="624"> <table border="1" cellpadding="7" cellspacing="1" width="100%">
<tr> <tr>
<td valign="top" width="45%"><p align="center">Expression.</p> <td valign="top" width="37%"><p align="center">Expression.</p>
</td> </td>
<td valign="top" width="45%"><p align="center">Description.</p> <td valign="top" width="37%"><p align="center">Description.</p>
</td> </td>
<td valign="top" width="33%"><p align="center">Compiler.</p> <td valign="top" width="27%"><p align="center">Compiler.</p>
</td> </td>
</tr> </tr>
<tr> <tr>
<td valign="top" width="45%"><code>is_const&lt;T&gt;::value</code></td> <td valign="top" width="37%"><code>is_const&lt;T&gt;::value</code></td>
<td valign="top" width="45%">True if type T is top-level <td valign="top" width="37%">True if type T is top-level
const qualified.</td> const qualified.</td>
<td valign="top" width="33%"><p align="center">P</p> <td valign="top" width="27%"><p align="center">P</p>
</td> </td>
</tr> </tr>
<tr> <tr>
<td valign="top" width="45%"><code>is_volatile&lt;T&gt;::value</code></td> <td valign="top" width="37%"><code>is_volatile&lt;T&gt;::value</code></td>
<td valign="top" width="45%">True if type T is top-level <td valign="top" width="37%">True if type T is top-level
volatile qualified.</td> volatile qualified.</td>
<td valign="top" width="33%"><p align="center">P</p> <td valign="top" width="27%"><p align="center">P</p>
</td>
</tr>
<tr>
<td valign="top" width="45%"><code>is_same&lt;T,U&gt;::value</code></td>
<td valign="top" width="45%">True if T and U are the same
type.</td>
<td valign="top" width="33%"><p align="center">P</p>
</td> </td>
</tr> </tr>
</table> </table>
@ -152,7 +186,7 @@ on a type (see 3.93).</p>
<p>The following will only ever be true for cv-unqualified types; <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> these are closely based on the section 3.9 of the C++ Standard.</p>
<table border="1" cellpadding="7" cellspacing="1" width="624"> <table border="1" cellpadding="7" cellspacing="1" width="100%">
<tr> <tr>
<td valign="top" width="45%"><p align="center">Expression.</p> <td valign="top" width="45%"><p align="center">Expression.</p>
</td> </td>
@ -291,7 +325,7 @@ these are closely based on the section 3.9 of the C++ Standard.</p>
<p>The following will only ever be true for cv-unqualified types, <p>The following will only ever be true for cv-unqualified types,
as defined by the Standard.&nbsp;</p> as defined by the Standard.&nbsp;</p>
<table border="1" cellpadding="7" cellspacing="1" width="624"> <table border="1" cellpadding="7" cellspacing="1" width="100%">
<tr> <tr>
<td valign="top" width="45%"><p align="center">Expression</p> <td valign="top" width="45%"><p align="center">Expression</p>
</td> </td>
@ -365,7 +399,7 @@ as defined by the Standard.&nbsp;</p>
is true then <code>class_name&lt;cv-qualified-T&gt;::value</code> is true then <code>class_name&lt;cv-qualified-T&gt;::value</code>
will also be true.</p> will also be true.</p>
<table border="1" cellpadding="7" cellspacing="1" width="624"> <table border="1" cellpadding="7" cellspacing="1" width="100%">
<tr> <tr>
<td valign="top" width="45%"><p align="center">Expression</p> <td valign="top" width="45%"><p align="center">Expression</p>
</td> </td>
@ -582,7 +616,7 @@ Hinnant and John Maddock.</p>
<p>Maintained by <a href="mailto:John_Maddock@compuserve.com">John <p>Maintained by <a href="mailto:John_Maddock@compuserve.com">John
Maddock</a>, the latest version of this file can be found at <a Maddock</a>, the latest version of this file can be found at <a
href="http://www.boost.org">www.boost.org</a>, and the boost href="http://www.boost.org/">www.boost.org</a>, and the boost
discussion list at <a href="http://www.egroups.com/list/boost">www.egroups.com/list/boost</a>.</p> discussion list at <a href="http://www.egroups.com/list/boost">www.egroups.com/list/boost</a>.</p>
</body> </body>
</html> </html>

View File

@ -5,6 +5,8 @@
// warranty, and with no claim as to its suitability for any purpose. // warranty, and with no claim as to its suitability for any purpose.
/* Release notes: /* Release notes:
31st July 2000:
Added extra tests for is_empty, is_convertible, alignment_of.
23rd July 2000: 23rd July 2000:
Removed all call_traits tests to call_traits_test.cpp Removed all call_traits tests to call_traits_test.cpp
Removed all compressed_pair tests to compressed_pair_tests.cpp Removed all compressed_pair tests to compressed_pair_tests.cpp
@ -570,7 +572,12 @@ int main()
align_test(char); align_test(char);
align_test(double); align_test(double);
align_test(int[4]); align_test(int[4]);
//align_test(int&); align_test(int(*)(int));
#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
align_test(char&);
align_test(char (&)(int));
align_test(char(&)[4]);
#endif
align_test(int*); align_test(int*);
//align_test(const int); //align_test(const int);
align_test(VB); align_test(VB);

105
type_traits_test.hpp Normal file
View File

@ -0,0 +1,105 @@
// boost::compressed_pair test program
// (C) Copyright John Maddock 2000. Permission to copy, use, modify, sell and
// distribute this software is granted provided this copyright notice appears
// in all copies. This software is provided "as is" without express or implied
// warranty, and with no claim as to its suitability for any purpose.
#ifndef BOOST_TYPE_TRAITS_TEST_HPP
#define BOOST_TYPE_TRAITS_TEST_HPP
//
// this one is here just to suppress warnings:
//
template <class T>
bool do_compare(T i, T j)
{
return i == j;
}
//
// this one is to verify that a constant is indeed a
// constant-integral-expression:
//
template <int>
struct ct_checker
{
};
#define BOOST_DO_JOIN( X, Y ) BOOST_DO_JOIN2(X,Y)
#define BOOST_DO_JOIN2(X, Y) X ## Y
#define BOOST_JOIN( X, Y ) BOOST_DO_JOIN( X, Y )
#define value_test(v, x) ++test_count;\
typedef ct_checker<(x)> BOOST_JOIN(this_is_a_compile_time_check_, __LINE__);\
if(!do_compare((int)v,(int)x)){++failures; std::cout << "checking value of " << #x << "...failed" << std::endl;}
#define value_fail(v, x) ++test_count; ++failures; std::cout << "checking value of " << #x << "...failed" << std::endl;
#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
#define type_test(v, x) ++test_count;\
if(do_compare(boost::is_same<v, x>::value, false)){\
++failures; \
std::cout << "checking type of " << #x << "...failed" << std::endl; \
std::cout << " expected type was " << #v << std::endl; \
std::cout << " " << typeid(boost::is_same<v, x>).name() << "::value is false" << std::endl; }
#else
#define type_test(v, x) ++test_count;\
if(typeid(v) != typeid(x)){\
++failures; \
std::cout << "checking type of " << #x << "...failed" << std::endl; \
std::cout << " expected type was " << #v << std::endl; \
std::cout << " " << "typeid(" #v ") != typeid(" #x ")" << std::endl; }
#endif
template <class T>
struct test_align
{
struct padded
{
char c;
T t;
};
static void do_it()
{
padded p;
unsigned a = reinterpret_cast<char*>(&(p.t)) - reinterpret_cast<char*>(&p);
value_test(a, boost::alignment_of<T>::value);
}
};
#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
template <class T>
struct test_align<T&>
{
static void do_it()
{
//
// we can't do the usual test because we can't take the address
// of a reference, so check that the result is the same as for a
// pointer type instead:
value_test(boost::alignment_of<T*>::value, boost::alignment_of<T&>::value);
}
};
#endif
#define align_test(T) test_align<T>::do_it()
//
// define tests here
unsigned failures = 0;
unsigned test_count = 0;
//
// turn off some warnings:
#ifdef __BORLANDC__
#pragma option -w-8004
#endif
#ifdef BOOST_MSVC
#pragma warning (disable: 4018)
#endif
#endif // BOOST_TYPE_TRAITS_TEST_HPP