Added traits classes:

is_base_and_derived
	has_nothrow_construct
	has_nothrow_copy
	has_nothrow_assign


[SVN r12213]
This commit is contained in:
John Maddock
2002-01-04 12:45:46 +00:00
parent 0482816876
commit 7a8b460ce8
7 changed files with 199 additions and 16 deletions

View File

@@ -228,6 +228,35 @@ struct is_convertible<void, void>
#endif // is_convertible
template <class Base, class Derived>
struct is_base_and_derived
{
BOOST_STATIC_CONSTANT(bool, value = (::boost::is_convertible<Derived*,Base*>::value));
};
#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
template <class Base, class Derived>
struct is_base_and_derived<Base&, Derived>
{
BOOST_STATIC_CONSTANT(bool, value = false);
};
template <class Base, class Derived>
struct is_base_and_derived<Base, Derived&>
{
BOOST_STATIC_CONSTANT(bool, value = false);
};
template <class Base, class Derived>
struct is_base_and_derived<Base&, Derived&>
{
BOOST_STATIC_CONSTANT(bool, value = false);
};
template <class Base>
struct is_base_and_derived<Base, void>
{
BOOST_STATIC_CONSTANT(bool, value = false);
};
#endif
} // namespace boost
#endif // include guard

View File

@@ -87,6 +87,8 @@ namespace boost{
// conversion_traits.hpp:
template <class From, class To>
struct is_convertible;
template <class Base, class Derived>
struct is_base_and_derived;
// alignment_traits.hpp:
template <class T>
struct alignment_of;
@@ -113,6 +115,12 @@ template <class T>
struct remove_volatile;
template <class T>
struct remove_cv;
template <class T>
struct add_const;
template <class T>
struct add_volatile;
template <class T>
struct add_cv;
// composite_traits.hpp:
template <class T>
@@ -150,6 +158,12 @@ struct has_trivial_assign;
template <class T>
struct has_trivial_destructor;
template <class T>
struct has_nothrow_constructor;
template <class T>
struct has_nothrow_copy;
template <class T>
struct has_nothrow_assign;
template <class T>
struct is_empty;
// transform_traits.hpp:

View File

@@ -217,6 +217,42 @@ struct has_trivial_destructor
>::value));
};
/**********************************************
*
* has_nothrow_constructor
*
**********************************************/
template <typename T>
struct has_nothrow_constructor
{
BOOST_STATIC_CONSTANT(bool, value =
(::boost::has_trivial_constructor<T>::value));
};
/**********************************************
*
* has_nothrow_copy
*
**********************************************/
template <typename T>
struct has_nothrow_copy
{
BOOST_STATIC_CONSTANT(bool, value =
(::boost::has_trivial_copy<T>::value));
};
/**********************************************
*
* has_nothrow_assign
*
**********************************************/
template <typename T>
struct has_nothrow_assign
{
BOOST_STATIC_CONSTANT(bool, value =
(::boost::has_trivial_assign<T>::value));
};
/**********************************************
*
* is_empty

View File

@@ -310,7 +310,7 @@ union empty_POD_union_UDT{};
class Base { };
class Deriverd : public Base { };
class Derived : public Base { };
class NonDerived { };

View File

@@ -452,6 +452,33 @@ has.</p>
</td>
<td valign="top" width="5%">&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td valign="top" bgcolor="#C0C0C0"><code>::boost::has_nothrow_constructor&lt;T&gt;::value</code></td>
<td bgcolor="#C0C0C0">True if T has a non-throwing
default constructor.</td>
<td bgcolor="#C0C0C0">&nbsp;</td>
<td align="center" bgcolor="#C0C0C0">PC</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td valign="top" bgcolor="#C0C0C0"><code>::boost::has_nothrow_copy&lt;T&gt;::value</code></td>
<td bgcolor="#C0C0C0">True if T has a non-throwing copy
constructor.</td>
<td bgcolor="#C0C0C0">&nbsp;</td>
<td align="center" bgcolor="#C0C0C0">PC</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td valign="top" bgcolor="#C0C0C0"><code>::boost::has_nothrow_assign&lt;T&gt;::value</code></td>
<td bgcolor="#C0C0C0">True if T has a non-throwing
assignment operator.</td>
<td bgcolor="#C0C0C0">&nbsp;</td>
<td align="center" bgcolor="#C0C0C0">PC</td>
<td>&nbsp;</td>
</tr>
</table>
<p>&nbsp;</p>
@@ -505,6 +532,15 @@ relationship between two types:</p>
compiler, for constructor-based conversions.</td>
<td valign="top" width="5%">&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td valign="top" bgcolor="#C0C0C0"><code>::boost::is_base_and_derived&lt;T,U&gt;::value</code></td>
<td bgcolor="#C0C0C0">Evaluates to true if type T is a
base class to type U.</td>
<td align="center" bgcolor="#C0C0C0">10</td>
<td align="center" bgcolor="#C0C0C0">P</td>
<td>&nbsp;</td>
</tr>
</table>
<p>&nbsp;</p>

View File

@@ -12,11 +12,11 @@
int cpp_main(int argc, char* argv[])
{
value_test(true, (boost::is_convertible<Deriverd,Base>::value));
value_test(true, (boost::is_convertible<Deriverd,Deriverd>::value));
value_test(true, (boost::is_convertible<Derived,Base>::value));
value_test(true, (boost::is_convertible<Derived,Derived>::value));
value_test(true, (boost::is_convertible<Base,Base>::value));
value_test(false, (boost::is_convertible<Base,Deriverd>::value));
value_test(true, (boost::is_convertible<Deriverd,Deriverd>::value));
value_test(false, (boost::is_convertible<Base,Derived>::value));
value_test(true, (boost::is_convertible<Derived,Derived>::value));
value_test(false, (boost::is_convertible<NonDerived,Base>::value));
value_test(false, (boost::is_convertible<boost::noncopyable, int>::value));
value_test(true, (boost::is_convertible<float,int>::value));
@@ -26,14 +26,14 @@ int cpp_main(int argc, char* argv[])
value_test(true, (boost::is_convertible<void,void>::value));
#endif
value_test(true, (boost::is_convertible<enum1, int>::value));
value_test(true, (boost::is_convertible<Deriverd*, Base*>::value));
value_test(false, (boost::is_convertible<Base*, Deriverd*>::value));
value_test(true, (boost::is_convertible<Deriverd&, Base&>::value));
value_test(false, (boost::is_convertible<Base&, Deriverd&>::value));
value_test(true, (boost::is_convertible<const Deriverd*, const Base*>::value));
value_test(false, (boost::is_convertible<const Base*, const Deriverd*>::value));
value_test(true, (boost::is_convertible<const Deriverd&, const Base&>::value));
value_test(false, (boost::is_convertible<const Base&, const Deriverd&>::value));
value_test(true, (boost::is_convertible<Derived*, Base*>::value));
value_test(false, (boost::is_convertible<Base*, Derived*>::value));
value_test(true, (boost::is_convertible<Derived&, Base&>::value));
value_test(false, (boost::is_convertible<Base&, Derived&>::value));
value_test(true, (boost::is_convertible<const Derived*, const Base*>::value));
value_test(false, (boost::is_convertible<const Base*, const Derived*>::value));
value_test(true, (boost::is_convertible<const Derived&, const Base&>::value));
value_test(false, (boost::is_convertible<const Base&, const Derived&>::value));
value_test(false, (boost::is_convertible<const int *, int*>::value));
value_test(false, (boost::is_convertible<const int&, int&>::value));
@@ -52,9 +52,21 @@ int cpp_main(int argc, char* argv[])
value_test(false, (boost::is_convertible<non_pointer, int*>::value));
value_test(true, (boost::is_convertible<non_int_pointer, int*>::value));
value_test(true, (boost::is_convertible<non_int_pointer, void*>::value));
value_test(true, (boost::is_convertible<int, int_constructible>::value));
//value_test(true, (boost::is_convertible<int, int_constructible>::value));
value_test(false, (boost::is_convertible<test_abc1&, test_abc2&>::value));
value_test(false, (boost::is_base_and_derived<Derived,Base>::value));
value_test(true, (boost::is_base_and_derived<Derived,Derived>::value));
value_test(true, (boost::is_base_and_derived<Base,Base>::value));
value_test(true, (boost::is_base_and_derived<Base,Derived>::value));
value_test(false, (boost::is_base_and_derived<NonDerived,Base>::value));
#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
value_test(false, (boost::is_base_and_derived<Base&,Derived>::value));
value_test(false, (boost::is_base_and_derived<Base&,Derived&>::value));
value_test(false, (boost::is_base_and_derived<Base,Derived&>::value));
value_test(false, (boost::is_base_and_derived<Base,void>::value));
#endif
return check_result(argc, argv);
}

View File

@@ -183,6 +183,62 @@ int cpp_main(int argc, char* argv[])
value_test(false, boost::has_trivial_destructor<test_abc1>::value)
#endif
value_test(true, boost::has_nothrow_constructor<int>::value)
value_test(true, boost::has_nothrow_constructor<int*>::value)
value_test(true, boost::has_nothrow_constructor<int*const>::value)
value_test(true, boost::has_nothrow_constructor<const int>::value)
value_test(true, boost::has_nothrow_constructor<volatile int>::value)
value_test(true, boost::has_nothrow_constructor<int[2]>::value)
value_test(true, boost::has_nothrow_constructor<int[3][2]>::value)
value_test(true, boost::has_nothrow_constructor<int[2][4][5][6][3]>::value)
value_test(true, boost::has_nothrow_constructor<f1>::value)
value_test(true, boost::has_nothrow_constructor<mf2>::value)
value_test(false, boost::has_nothrow_constructor<UDT>::value)
soft_value_test(true, boost::has_nothrow_constructor<empty_UDT>::value)
value_test(true, boost::has_nothrow_constructor<enum_UDT>::value)
value_test(true, boost::has_nothrow_constructor<void>::value)
#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
value_test(false, boost::has_nothrow_constructor<test_abc1>::value)
#endif
value_test(true, boost::has_nothrow_copy<int>::value)
value_test(true, boost::has_nothrow_copy<int*>::value)
value_test(true, boost::has_nothrow_copy<int*const>::value)
value_test(true, boost::has_nothrow_copy<const int>::value)
// Steve: was 'false' -- should be 'true' via 3.9p3, 3.9p10
value_test(false, boost::has_nothrow_copy<volatile int>::value)
value_test(true, boost::has_nothrow_copy<int[2]>::value)
value_test(true, boost::has_nothrow_copy<int[3][2]>::value)
value_test(true, boost::has_nothrow_copy<int[2][4][5][6][3]>::value)
value_test(true, boost::has_nothrow_copy<f1>::value)
value_test(true, boost::has_nothrow_copy<mf2>::value)
value_test(false, boost::has_nothrow_copy<UDT>::value)
soft_value_test(true, boost::has_nothrow_copy<empty_UDT>::value)
value_test(true, boost::has_nothrow_copy<enum_UDT>::value)
value_test(true, boost::has_nothrow_copy<void>::value)
#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
value_test(false, boost::has_nothrow_copy<test_abc1>::value)
#endif
value_test(true, boost::has_nothrow_assign<int>::value)
value_test(true, boost::has_nothrow_assign<int*>::value)
value_test(false, boost::has_nothrow_assign<int*const>::value)
value_test(false, boost::has_nothrow_assign<const int>::value)
// Steve: was 'false' -- should be 'true' via 3.9p3, 3.9p10
value_test(false, boost::has_nothrow_assign<volatile int>::value)
value_test(true, boost::has_nothrow_assign<int[2]>::value)
value_test(true, boost::has_nothrow_assign<int[3][2]>::value)
value_test(true, boost::has_nothrow_assign<int[2][4][5][6][3]>::value)
value_test(true, boost::has_nothrow_assign<f1>::value)
value_test(true, boost::has_nothrow_assign<mf2>::value)
value_test(false, boost::has_nothrow_assign<UDT>::value)
soft_value_test(true, boost::has_nothrow_assign<empty_UDT>::value)
value_test(true, boost::has_nothrow_assign<enum_UDT>::value)
value_test(true, boost::has_nothrow_assign<void>::value)
#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
value_test(false, boost::has_nothrow_assign<test_abc1>::value)
#endif
soft_value_test(false, boost::is_empty<int>::value)
soft_value_test(false, boost::is_empty<int*>::value)
soft_value_test(false, boost::is_empty<int&>::value)
@@ -220,7 +276,7 @@ int cpp_main(int argc, char* argv[])
// define the number of failures expected for given compilers:
#ifdef __BORLANDC__
// can't handle enum's or classes that are POD's
unsigned int expected_failures = 6;
unsigned int expected_failures = 9;
#elif defined(__SUNPRO_CC)
#if (__SUNPRO_CC <= 0x520)
unsigned int expected_failures = 55;
@@ -231,7 +287,7 @@ unsigned int expected_failures = 20;
unsigned int expected_failures = 10;
#elif defined(BOOST_MSVC)
// can't handle classes that are POD's or arrays that are POD's
unsigned int expected_failures = 15;
unsigned int expected_failures = 24;
#else
unsigned int expected_failures = 0;
#endif