From 7a8b460ce8fd036910551b5ab74429b3273270bc Mon Sep 17 00:00:00 2001 From: John Maddock Date: Fri, 4 Jan 2002 12:45:46 +0000 Subject: [PATCH] Added traits classes: is_base_and_derived has_nothrow_construct has_nothrow_copy has_nothrow_assign [SVN r12213] --- .../boost/type_traits/conversion_traits.hpp | 29 +++++++++ include/boost/type_traits/fwd.hpp | 14 +++++ include/boost/type_traits/object_traits.hpp | 36 +++++++++++ .../boost/type_traits/type_traits_test.hpp | 2 +- index.htm | 36 +++++++++++ tests/is_convertible_test.cpp | 38 ++++++++---- tests/object_type_traits_test.cpp | 60 ++++++++++++++++++- 7 files changed, 199 insertions(+), 16 deletions(-) diff --git a/include/boost/type_traits/conversion_traits.hpp b/include/boost/type_traits/conversion_traits.hpp index 3d640a5..3beb5a5 100644 --- a/include/boost/type_traits/conversion_traits.hpp +++ b/include/boost/type_traits/conversion_traits.hpp @@ -228,6 +228,35 @@ struct is_convertible #endif // is_convertible +template +struct is_base_and_derived +{ + BOOST_STATIC_CONSTANT(bool, value = (::boost::is_convertible::value)); +}; + +#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION +template +struct is_base_and_derived +{ + BOOST_STATIC_CONSTANT(bool, value = false); +}; +template +struct is_base_and_derived +{ + BOOST_STATIC_CONSTANT(bool, value = false); +}; +template +struct is_base_and_derived +{ + BOOST_STATIC_CONSTANT(bool, value = false); +}; +template +struct is_base_and_derived +{ + BOOST_STATIC_CONSTANT(bool, value = false); +}; +#endif + } // namespace boost #endif // include guard diff --git a/include/boost/type_traits/fwd.hpp b/include/boost/type_traits/fwd.hpp index c492069..1b14652 100644 --- a/include/boost/type_traits/fwd.hpp +++ b/include/boost/type_traits/fwd.hpp @@ -87,6 +87,8 @@ namespace boost{ // conversion_traits.hpp: template struct is_convertible; +template +struct is_base_and_derived; // alignment_traits.hpp: template struct alignment_of; @@ -113,6 +115,12 @@ template struct remove_volatile; template struct remove_cv; +template +struct add_const; +template +struct add_volatile; +template +struct add_cv; // composite_traits.hpp: template @@ -150,6 +158,12 @@ struct has_trivial_assign; template struct has_trivial_destructor; template +struct has_nothrow_constructor; +template +struct has_nothrow_copy; +template +struct has_nothrow_assign; +template struct is_empty; // transform_traits.hpp: diff --git a/include/boost/type_traits/object_traits.hpp b/include/boost/type_traits/object_traits.hpp index c55314e..4919b01 100644 --- a/include/boost/type_traits/object_traits.hpp +++ b/include/boost/type_traits/object_traits.hpp @@ -217,6 +217,42 @@ struct has_trivial_destructor >::value)); }; +/********************************************** + * + * has_nothrow_constructor + * + **********************************************/ +template +struct has_nothrow_constructor +{ + BOOST_STATIC_CONSTANT(bool, value = + (::boost::has_trivial_constructor::value)); +}; + +/********************************************** + * + * has_nothrow_copy + * + **********************************************/ +template +struct has_nothrow_copy +{ + BOOST_STATIC_CONSTANT(bool, value = + (::boost::has_trivial_copy::value)); +}; + +/********************************************** + * + * has_nothrow_assign + * + **********************************************/ +template +struct has_nothrow_assign +{ + BOOST_STATIC_CONSTANT(bool, value = + (::boost::has_trivial_assign::value)); +}; + /********************************************** * * is_empty diff --git a/include/boost/type_traits/type_traits_test.hpp b/include/boost/type_traits/type_traits_test.hpp index be8c672..a6f1cd0 100644 --- a/include/boost/type_traits/type_traits_test.hpp +++ b/include/boost/type_traits/type_traits_test.hpp @@ -310,7 +310,7 @@ union empty_POD_union_UDT{}; class Base { }; -class Deriverd : public Base { }; +class Derived : public Base { }; class NonDerived { }; diff --git a/index.htm b/index.htm index ef8d584..5a9f869 100644 --- a/index.htm +++ b/index.htm @@ -452,6 +452,33 @@ has.

  + +   + ::boost::has_nothrow_constructor<T>::value + True if T has a non-throwing + default constructor. +   + PC +   + + +   + ::boost::has_nothrow_copy<T>::value + True if T has a non-throwing copy + constructor. +   + PC +   + + +   + ::boost::has_nothrow_assign<T>::value + True if T has a non-throwing + assignment operator. +   + PC +   +

 

@@ -505,6 +532,15 @@ relationship between two types:

compiler, for constructor-based conversions.   + +   + ::boost::is_base_and_derived<T,U>::value + Evaluates to true if type T is a + base class to type U. + 10 + P +   +

 

diff --git a/tests/is_convertible_test.cpp b/tests/is_convertible_test.cpp index 604dda6..266fd86 100644 --- a/tests/is_convertible_test.cpp +++ b/tests/is_convertible_test.cpp @@ -12,11 +12,11 @@ int cpp_main(int argc, char* argv[]) { - value_test(true, (boost::is_convertible::value)); - value_test(true, (boost::is_convertible::value)); + value_test(true, (boost::is_convertible::value)); + value_test(true, (boost::is_convertible::value)); value_test(true, (boost::is_convertible::value)); - value_test(false, (boost::is_convertible::value)); - value_test(true, (boost::is_convertible::value)); + value_test(false, (boost::is_convertible::value)); + value_test(true, (boost::is_convertible::value)); value_test(false, (boost::is_convertible::value)); value_test(false, (boost::is_convertible::value)); value_test(true, (boost::is_convertible::value)); @@ -26,14 +26,14 @@ int cpp_main(int argc, char* argv[]) value_test(true, (boost::is_convertible::value)); #endif value_test(true, (boost::is_convertible::value)); - value_test(true, (boost::is_convertible::value)); - value_test(false, (boost::is_convertible::value)); - value_test(true, (boost::is_convertible::value)); - value_test(false, (boost::is_convertible::value)); - value_test(true, (boost::is_convertible::value)); - value_test(false, (boost::is_convertible::value)); - value_test(true, (boost::is_convertible::value)); - value_test(false, (boost::is_convertible::value)); + value_test(true, (boost::is_convertible::value)); + value_test(false, (boost::is_convertible::value)); + value_test(true, (boost::is_convertible::value)); + value_test(false, (boost::is_convertible::value)); + value_test(true, (boost::is_convertible::value)); + value_test(false, (boost::is_convertible::value)); + value_test(true, (boost::is_convertible::value)); + value_test(false, (boost::is_convertible::value)); value_test(false, (boost::is_convertible::value)); value_test(false, (boost::is_convertible::value)); @@ -52,9 +52,21 @@ int cpp_main(int argc, char* argv[]) value_test(false, (boost::is_convertible::value)); value_test(true, (boost::is_convertible::value)); value_test(true, (boost::is_convertible::value)); - value_test(true, (boost::is_convertible::value)); + //value_test(true, (boost::is_convertible::value)); value_test(false, (boost::is_convertible::value)); + value_test(false, (boost::is_base_and_derived::value)); + value_test(true, (boost::is_base_and_derived::value)); + value_test(true, (boost::is_base_and_derived::value)); + value_test(true, (boost::is_base_and_derived::value)); + value_test(false, (boost::is_base_and_derived::value)); +#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION + value_test(false, (boost::is_base_and_derived::value)); + value_test(false, (boost::is_base_and_derived::value)); + value_test(false, (boost::is_base_and_derived::value)); + value_test(false, (boost::is_base_and_derived::value)); +#endif + return check_result(argc, argv); } diff --git a/tests/object_type_traits_test.cpp b/tests/object_type_traits_test.cpp index f90a36e..f5ca3a4 100644 --- a/tests/object_type_traits_test.cpp +++ b/tests/object_type_traits_test.cpp @@ -183,6 +183,62 @@ int cpp_main(int argc, char* argv[]) value_test(false, boost::has_trivial_destructor::value) #endif + value_test(true, boost::has_nothrow_constructor::value) + value_test(true, boost::has_nothrow_constructor::value) + value_test(true, boost::has_nothrow_constructor::value) + value_test(true, boost::has_nothrow_constructor::value) + value_test(true, boost::has_nothrow_constructor::value) + value_test(true, boost::has_nothrow_constructor::value) + value_test(true, boost::has_nothrow_constructor::value) + value_test(true, boost::has_nothrow_constructor::value) + value_test(true, boost::has_nothrow_constructor::value) + value_test(true, boost::has_nothrow_constructor::value) + value_test(false, boost::has_nothrow_constructor::value) + soft_value_test(true, boost::has_nothrow_constructor::value) + value_test(true, boost::has_nothrow_constructor::value) + value_test(true, boost::has_nothrow_constructor::value) +#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION + value_test(false, boost::has_nothrow_constructor::value) +#endif + + value_test(true, boost::has_nothrow_copy::value) + value_test(true, boost::has_nothrow_copy::value) + value_test(true, boost::has_nothrow_copy::value) + value_test(true, boost::has_nothrow_copy::value) + // Steve: was 'false' -- should be 'true' via 3.9p3, 3.9p10 + value_test(false, boost::has_nothrow_copy::value) + value_test(true, boost::has_nothrow_copy::value) + value_test(true, boost::has_nothrow_copy::value) + value_test(true, boost::has_nothrow_copy::value) + value_test(true, boost::has_nothrow_copy::value) + value_test(true, boost::has_nothrow_copy::value) + value_test(false, boost::has_nothrow_copy::value) + soft_value_test(true, boost::has_nothrow_copy::value) + value_test(true, boost::has_nothrow_copy::value) + value_test(true, boost::has_nothrow_copy::value) +#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION + value_test(false, boost::has_nothrow_copy::value) +#endif + + value_test(true, boost::has_nothrow_assign::value) + value_test(true, boost::has_nothrow_assign::value) + value_test(false, boost::has_nothrow_assign::value) + value_test(false, boost::has_nothrow_assign::value) + // Steve: was 'false' -- should be 'true' via 3.9p3, 3.9p10 + value_test(false, boost::has_nothrow_assign::value) + value_test(true, boost::has_nothrow_assign::value) + value_test(true, boost::has_nothrow_assign::value) + value_test(true, boost::has_nothrow_assign::value) + value_test(true, boost::has_nothrow_assign::value) + value_test(true, boost::has_nothrow_assign::value) + value_test(false, boost::has_nothrow_assign::value) + soft_value_test(true, boost::has_nothrow_assign::value) + value_test(true, boost::has_nothrow_assign::value) + value_test(true, boost::has_nothrow_assign::value) +#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION + value_test(false, boost::has_nothrow_assign::value) +#endif + soft_value_test(false, boost::is_empty::value) soft_value_test(false, boost::is_empty::value) soft_value_test(false, boost::is_empty::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