From 7191a5eaea014f9461ebc73856751bf56df5c1d5 Mon Sep 17 00:00:00 2001 From: Dave Abrahams Date: Fri, 22 Feb 2002 01:04:45 +0000 Subject: [PATCH] ---------------------------------------------------------------------- Fixed is_POD for array types on compilers without partial specialization. Caused tests to fail when the number of failures doesn't exactly meet expectations. Modified Files: boost/type_traits/object_traits.hpp boost/type_traits/type_traits_test.hpp libs/type_traits/tests/object_type_traits_test.cpp ---------------------------------------------------------------------- [SVN r12887] --- include/boost/type_traits/object_traits.hpp | 85 ++++++++++++++++++- .../boost/type_traits/type_traits_test.hpp | 2 +- tests/object_type_traits_test.cpp | 2 +- 3 files changed, 83 insertions(+), 6 deletions(-) diff --git a/include/boost/type_traits/object_traits.hpp b/include/boost/type_traits/object_traits.hpp index 50cc36f..43f4656 100644 --- a/include/boost/type_traits/object_traits.hpp +++ b/include/boost/type_traits/object_traits.hpp @@ -133,21 +133,98 @@ template struct is_compound * is_POD * **********************************************/ + +#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION template struct is_POD { - BOOST_STATIC_CONSTANT(bool, value = - (::boost::type_traits::ice_or< + BOOST_STATIC_CONSTANT( + bool, value = + (::boost::type_traits::ice_or< ::boost::is_scalar::value, ::boost::is_void::value, BOOST_IS_POD(T) - >::value)); + >::value)); }; -#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION + template struct is_POD { BOOST_STATIC_CONSTANT(bool, value = ::boost::is_POD::value); }; +#else +namespace detail +{ + template struct is_POD_helper; +} + +template struct is_POD +{ + BOOST_STATIC_CONSTANT( + bool, value = ( + ::boost::detail::is_POD_helper< + ::boost::is_array::value + >::template apply::value + ) + ); +}; + +namespace detail +{ + template + struct is_POD_helper + { + template struct apply + { + BOOST_STATIC_CONSTANT( + bool, value = + (::boost::type_traits::ice_or< + ::boost::is_scalar::value, + ::boost::is_void::value, + BOOST_IS_POD(T) + >::value)); + }; + }; + + template + struct bool_to_type + { + typedef ::boost::type_traits::no_type type; + }; + + template <> + struct bool_to_type + { + typedef ::boost::type_traits::yes_type type; + }; + + template + struct is_POD_array_helper + { + typedef +#if !defined(__BORLANDC__) || __BORLANDC__ > 0x551 + typename +#endif + ::boost::detail::bool_to_type<(::boost::is_POD::value)>::type type; + + type instance() const; + }; + + template + is_POD_array_helper is_POD_array(T*); + + template <> + struct is_POD_helper + { + template struct apply + { + static T& help(); + + BOOST_STATIC_CONSTANT( + bool, value = + sizeof(is_POD_array(help()).instance()) > 1); + }; + }; +} #endif /********************************************** diff --git a/include/boost/type_traits/type_traits_test.hpp b/include/boost/type_traits/type_traits_test.hpp index 81aa050..c5708c7 100644 --- a/include/boost/type_traits/type_traits_test.hpp +++ b/include/boost/type_traits/type_traits_test.hpp @@ -42,7 +42,7 @@ int check_result(int argc, char** argv) std::cout << "Press any key to continue..."; std::cin.get(); } - return (failures <= expected_failures) ? 0 : failures; + return (failures == expected_failures) ? 0 : (failures != 0) ? failures : -1; } diff --git a/tests/object_type_traits_test.cpp b/tests/object_type_traits_test.cpp index 8661561..00fa83c 100644 --- a/tests/object_type_traits_test.cpp +++ b/tests/object_type_traits_test.cpp @@ -305,7 +305,7 @@ unsigned int expected_failures = 25; 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 = 24; +unsigned int expected_failures = 16; #elif defined(__HP_aCC) unsigned int expected_failures = 2; #elif defined(__EDG_VERSION__)