From 713516cd7d89af1d50b4e95920302911a36d20cb Mon Sep 17 00:00:00 2001 From: John Maddock Date: Thu, 3 Apr 2008 16:41:43 +0000 Subject: [PATCH] Update the type_traits intrinsics support to include the gcc-4.3 intrinsics. Also added some braces to our testing macros to quieten gcc warnings. [SVN r44013] --- include/boost/type_traits/intrinsics.hpp | 34 +++++++++++++++++++ include/boost/type_traits/is_abstract.hpp | 11 +++++- .../boost/type_traits/is_base_and_derived.hpp | 12 ++++++- include/boost/type_traits/is_class.hpp | 11 ++++++ include/boost/type_traits/is_enum.hpp | 11 +++++- include/boost/type_traits/is_polymorphic.hpp | 12 +++++++ test/check_integral_constant.hpp | 8 ++++- 7 files changed, 95 insertions(+), 4 deletions(-) mode change 100755 => 100644 include/boost/type_traits/is_abstract.hpp diff --git a/include/boost/type_traits/intrinsics.hpp b/include/boost/type_traits/intrinsics.hpp index 3b48b47..a8cde36 100644 --- a/include/boost/type_traits/intrinsics.hpp +++ b/include/boost/type_traits/intrinsics.hpp @@ -31,6 +31,16 @@ // BOOST_HAS_NOTHROW_COPY(T) should evaluate to true if T(t) can not throw // BOOST_HAS_NOTHROW_ASSIGN(T) should evaluate to true if t = u can not throw // BOOST_HAS_VIRTUAL_DESTRUCTOR(T) should evaluate to true T has a virtual destructor +// +// The following can also be defined: when detected our implementation is greatly simplified. +// Note that unlike the macros above these do not have default definitions, so we can use +// #ifdef MACRONAME to detect when these are available. +// +// BOOST_IS_ABSTRACT(T) true if T is an abstract type +// BOOST_IS_BASE_OF(T,U) true if T is a base class of U +// BOOST_IS_CLASS(T) true if T is a class type +// BOOST_IS_ENUM(T) true is T is an enum +// BOOST_IS_POLYMORPHIC(T) true if T is a polymorphic type #ifdef BOOST_HAS_SGI_TYPE_TRAITS // Hook into SGI's __type_traits class, this will pick up user supplied @@ -101,6 +111,30 @@ # define BOOST_HAS_TYPE_TRAITS_INTRINSICS #endif +#if defined(__GNUC__) && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 3))) +# include +# include +# include + +# define BOOST_IS_UNION(T) __is_union(T) +# define BOOST_IS_POD(T) __is_pod(T) +# define BOOST_IS_EMPTY(T) __is_empty(T) +# define BOOST_HAS_TRIVIAL_CONSTRUCTOR(T) __has_trivial_constructor(T) +# define BOOST_HAS_TRIVIAL_COPY(T) (__has_trivial_copy(T) && !is_reference::value) +# define BOOST_HAS_TRIVIAL_ASSIGN(T) __has_trivial_assign(T) +# define BOOST_HAS_TRIVIAL_DESTRUCTOR(T) __has_trivial_destructor(T) +# define BOOST_HAS_NOTHROW_CONSTRUCTOR(T) __has_nothrow_constructor(T) +# define BOOST_HAS_NOTHROW_COPY(T) (__has_nothrow_copy(T) && !is_volatile::value && !is_reference::value) +# define BOOST_HAS_NOTHROW_ASSIGN(T) (__has_nothrow_assign(T) && !is_volatile::value) +# define BOOST_HAS_VIRTUAL_DESTRUCTOR(T) __has_virtual_destructor(T) + +# define BOOST_IS_ABSTRACT(T) __is_abstract(T) +# define BOOST_IS_BASE_OF(T,U) (__is_base_of(T,U) && !is_same::value) +# define BOOST_IS_CLASS(T) __is_class(T) +# define BOOST_IS_ENUM(T) __is_enum(T) +# define BOOST_IS_POLYMORPHIC(T) __is_polymorphic(T) +#endif + #ifndef BOOST_IS_UNION # define BOOST_IS_UNION(T) false #endif diff --git a/include/boost/type_traits/is_abstract.hpp b/include/boost/type_traits/is_abstract.hpp old mode 100755 new mode 100644 index c565f08..29d10c3 --- a/include/boost/type_traits/is_abstract.hpp +++ b/include/boost/type_traits/is_abstract.hpp @@ -48,6 +48,8 @@ // to degrade gracefully, rather than trash the compiler (John Maddock). // +#include +#ifndef BOOST_IS_ABSTRACT #include #include #include @@ -55,6 +57,7 @@ #ifdef BOOST_NO_IS_ABSTRACT #include #endif +#endif // should be the last #include #include @@ -62,7 +65,13 @@ namespace boost { namespace detail{ -#ifndef BOOST_NO_IS_ABSTRACT +#ifdef BOOST_IS_ABSTRACT +template +struct is_abstract_imp +{ + BOOST_STATIC_CONSTANT(bool, value = BOOST_IS_ABSTRACT(T)); +}; +#elif !defined(BOOST_NO_IS_ABSTRACT) template struct is_abstract_imp2 { diff --git a/include/boost/type_traits/is_base_and_derived.hpp b/include/boost/type_traits/is_base_and_derived.hpp index 6f3add2..0e195b3 100644 --- a/include/boost/type_traits/is_base_and_derived.hpp +++ b/include/boost/type_traits/is_base_and_derived.hpp @@ -9,6 +9,8 @@ #ifndef BOOST_TT_IS_BASE_AND_DERIVED_HPP_INCLUDED #define BOOST_TT_IS_BASE_AND_DERIVED_HPP_INCLUDED +#include +#ifndef BOOST_IS_BASE_OF #include #include #include @@ -16,6 +18,7 @@ #include #include #include +#endif // should be the last #include #include @@ -24,6 +27,7 @@ namespace boost { namespace detail { +#ifndef BOOST_IS_BASE_OF #if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x581)) \ && !BOOST_WORKAROUND(__SUNPRO_CC , <= 0x540) \ && !BOOST_WORKAROUND(__EDG_VERSION__, <= 243) \ @@ -214,7 +218,13 @@ struct is_base_and_derived_impl BOOST_STATIC_CONSTANT(bool, value = bound_type::value); }; - +#else +template +struct is_base_and_derived_impl +{ + BOOST_STATIC_CONSTANT(bool, value = BOOST_IS_BASE_OF(B,D)); +}; +#endif } // namespace detail BOOST_TT_AUX_BOOL_TRAIT_DEF2( diff --git a/include/boost/type_traits/is_class.hpp b/include/boost/type_traits/is_class.hpp index 05d96de..63a0c6a 100644 --- a/include/boost/type_traits/is_class.hpp +++ b/include/boost/type_traits/is_class.hpp @@ -11,6 +11,8 @@ #define BOOST_TT_IS_CLASS_HPP_INCLUDED #include +#include +#ifndef BOOST_IS_CLASS # include # include # include @@ -28,6 +30,7 @@ #ifdef __EDG_VERSION__ # include #endif +#endif // BOOST_IS_CLASS // should be the last #include #include @@ -36,6 +39,7 @@ namespace boost { namespace detail { +#ifndef BOOST_IS_CLASS #ifdef BOOST_TT_HAS_CONFORMING_IS_CLASS_IMPLEMENTATION // This is actually the conforming implementation which works with @@ -111,6 +115,13 @@ struct is_class_impl }; # endif // BOOST_TT_HAS_CONFORMING_IS_CLASS_IMPLEMENTATION +# else // BOOST_IS_CLASS +template +struct is_class_impl +{ + BOOST_STATIC_CONSTANT(bool, value = BOOST_IS_CLASS(T)); +}; +# endif // BOOST_IS_CLASS } // namespace detail diff --git a/include/boost/type_traits/is_enum.hpp b/include/boost/type_traits/is_enum.hpp index c913975..86fa66d 100644 --- a/include/boost/type_traits/is_enum.hpp +++ b/include/boost/type_traits/is_enum.hpp @@ -11,6 +11,8 @@ #ifndef BOOST_TT_IS_ENUM_HPP_INCLUDED #define BOOST_TT_IS_ENUM_HPP_INCLUDED +#include +#ifndef BOOST_IS_ENUM #include #include #include @@ -24,13 +26,14 @@ # include # include #endif - +#endif // should be the last #include #include namespace boost { +#ifndef BOOST_IS_ENUM #if !(defined(__BORLANDC__) && (__BORLANDC__ <= 0x551)) namespace detail { @@ -173,6 +176,12 @@ BOOST_TT_AUX_BOOL_TRAIT_DEF1(is_enum,T,false) #endif +#else // BOOST_IS_ENUM + +BOOST_TT_AUX_BOOL_TRAIT_DEF1(is_enum,T,BOOST_IS_ENUM(T)) + +#endif + } // namespace boost #include diff --git a/include/boost/type_traits/is_polymorphic.hpp b/include/boost/type_traits/is_polymorphic.hpp index c312622..8fcc69e 100644 --- a/include/boost/type_traits/is_polymorphic.hpp +++ b/include/boost/type_traits/is_polymorphic.hpp @@ -8,13 +8,19 @@ #ifndef BOOST_TT_IS_POLYMORPHIC_HPP #define BOOST_TT_IS_POLYMORPHIC_HPP +#include +#ifndef BOOST_IS_POLYMORPHIC #include #include +#endif // should be the last #include #include #include namespace boost{ + +#ifndef BOOST_IS_POLYMORPHIC + namespace detail{ template @@ -95,6 +101,12 @@ struct is_polymorphic_imp BOOST_TT_AUX_BOOL_TRAIT_DEF1(is_polymorphic,T,::boost::detail::is_polymorphic_imp::value) +#else // BOOST_IS_POLYMORPHIC + +BOOST_TT_AUX_BOOL_TRAIT_DEF1(is_polymorphic,T,BOOST_IS_POLYMORPHIC(T)) + +#endif + } // namespace boost #include diff --git a/test/check_integral_constant.hpp b/test/check_integral_constant.hpp index 8cfd06a..754a170 100644 --- a/test/check_integral_constant.hpp +++ b/test/check_integral_constant.hpp @@ -59,10 +59,16 @@ namespace boost{ BOOST_CHECK_MESSAGE(true, "Validating Integral Constant Expression: \"" << BOOST_STRINGIZE(expression) << "\"");\ }\ if(!::boost::detail::tt_compare((int)expression, expected_value))\ + {\ if(!::boost::detail::tt_compare((int)expression, alternate_value))\ + {\ BOOST_CHECK_MESSAGE(false, "The expression: \"" << BOOST_STRINGIZE(expression) << "\" had an invalid value (found " << ::boost::detail::integral_constant<(int)(expression)>::value() << ", expected " << expected_value << ")" );\ + }\ else\ - BOOST_WARN_MESSAGE(false, "The expression: \"" << BOOST_STRINGIZE(expression) << "\" did not have the value we wish it to have (found " << ::boost::detail::integral_constant<(int)(expression)>::value() << ", expected " << expected_value << ")" ) + {\ + BOOST_WARN_MESSAGE(false, "The expression: \"" << BOOST_STRINGIZE(expression) << "\" did not have the value we wish it to have (found " << ::boost::detail::integral_constant<(int)(expression)>::value() << ", expected " << expected_value << ")" );\ + }\ + } }//detail