|
Boost-Commit : |
From: john_at_[hidden]
Date: 2008-04-03 12:41:44
Author: johnmaddock
Date: 2008-04-03 12:41:43 EDT (Thu, 03 Apr 2008)
New Revision: 44013
URL: http://svn.boost.org/trac/boost/changeset/44013
Log:
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.
Text files modified:
trunk/boost/type_traits/intrinsics.hpp | 34 ++++++++++++++++++++++++++++++++++
trunk/boost/type_traits/is_abstract.hpp | 11 ++++++++++-
trunk/boost/type_traits/is_base_and_derived.hpp | 12 +++++++++++-
trunk/boost/type_traits/is_class.hpp | 11 +++++++++++
trunk/boost/type_traits/is_enum.hpp | 11 ++++++++++-
trunk/boost/type_traits/is_polymorphic.hpp | 12 ++++++++++++
trunk/libs/type_traits/test/check_integral_constant.hpp | 8 +++++++-
7 files changed, 95 insertions(+), 4 deletions(-)
Modified: trunk/boost/type_traits/intrinsics.hpp
==============================================================================
--- trunk/boost/type_traits/intrinsics.hpp (original)
+++ trunk/boost/type_traits/intrinsics.hpp 2008-04-03 12:41:43 EDT (Thu, 03 Apr 2008)
@@ -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 <boost/type_traits/is_same.hpp>
+# include <boost/type_traits/is_reference.hpp>
+# include <boost/type_traits/is_volatile.hpp>
+
+# 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<T>::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<T>::value && !is_reference<T>::value)
+# define BOOST_HAS_NOTHROW_ASSIGN(T) (__has_nothrow_assign(T) && !is_volatile<T>::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<T,U>::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
Modified: trunk/boost/type_traits/is_abstract.hpp
==============================================================================
--- trunk/boost/type_traits/is_abstract.hpp (original)
+++ trunk/boost/type_traits/is_abstract.hpp 2008-04-03 12:41:43 EDT (Thu, 03 Apr 2008)
@@ -48,6 +48,8 @@
// to degrade gracefully, rather than trash the compiler (John Maddock).
//
+#include <boost/type_traits/intrinsics.hpp>
+#ifndef BOOST_IS_ABSTRACT
#include <boost/static_assert.hpp>
#include <boost/type_traits/detail/yes_no_type.hpp>
#include <boost/type_traits/is_class.hpp>
@@ -55,6 +57,7 @@
#ifdef BOOST_NO_IS_ABSTRACT
#include <boost/type_traits/is_polymorphic.hpp>
#endif
+#endif
// should be the last #include
#include <boost/type_traits/detail/bool_trait_def.hpp>
@@ -62,7 +65,13 @@
namespace boost {
namespace detail{
-#ifndef BOOST_NO_IS_ABSTRACT
+#ifdef BOOST_IS_ABSTRACT
+template <class T>
+struct is_abstract_imp
+{
+ BOOST_STATIC_CONSTANT(bool, value = BOOST_IS_ABSTRACT(T));
+};
+#elif !defined(BOOST_NO_IS_ABSTRACT)
template<class T>
struct is_abstract_imp2
{
Modified: trunk/boost/type_traits/is_base_and_derived.hpp
==============================================================================
--- trunk/boost/type_traits/is_base_and_derived.hpp (original)
+++ trunk/boost/type_traits/is_base_and_derived.hpp 2008-04-03 12:41:43 EDT (Thu, 03 Apr 2008)
@@ -9,6 +9,8 @@
#ifndef BOOST_TT_IS_BASE_AND_DERIVED_HPP_INCLUDED
#define BOOST_TT_IS_BASE_AND_DERIVED_HPP_INCLUDED
+#include <boost/type_traits/intrinsics.hpp>
+#ifndef BOOST_IS_BASE_OF
#include <boost/type_traits/is_class.hpp>
#include <boost/type_traits/is_same.hpp>
#include <boost/type_traits/is_convertible.hpp>
@@ -16,6 +18,7 @@
#include <boost/type_traits/remove_cv.hpp>
#include <boost/config.hpp>
#include <boost/static_assert.hpp>
+#endif
// should be the last #include
#include <boost/type_traits/detail/bool_trait_def.hpp>
@@ -24,6 +27,7 @@
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 @@
BOOST_STATIC_CONSTANT(bool, value = bound_type::value);
};
-
+#else
+template <typename B, typename D>
+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(
Modified: trunk/boost/type_traits/is_class.hpp
==============================================================================
--- trunk/boost/type_traits/is_class.hpp (original)
+++ trunk/boost/type_traits/is_class.hpp 2008-04-03 12:41:43 EDT (Thu, 03 Apr 2008)
@@ -11,6 +11,8 @@
#define BOOST_TT_IS_CLASS_HPP_INCLUDED
#include <boost/type_traits/config.hpp>
+#include <boost/type_traits/intrinsics.hpp>
+#ifndef BOOST_IS_CLASS
# include <boost/type_traits/is_union.hpp>
# include <boost/type_traits/detail/ice_and.hpp>
# include <boost/type_traits/detail/ice_not.hpp>
@@ -28,6 +30,7 @@
#ifdef __EDG_VERSION__
# include <boost/type_traits/remove_cv.hpp>
#endif
+#endif // BOOST_IS_CLASS
// should be the last #include
#include <boost/type_traits/detail/bool_trait_def.hpp>
@@ -36,6 +39,7 @@
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 @@
};
# endif // BOOST_TT_HAS_CONFORMING_IS_CLASS_IMPLEMENTATION
+# else // BOOST_IS_CLASS
+template <typename T>
+struct is_class_impl
+{
+ BOOST_STATIC_CONSTANT(bool, value = BOOST_IS_CLASS(T));
+};
+# endif // BOOST_IS_CLASS
} // namespace detail
Modified: trunk/boost/type_traits/is_enum.hpp
==============================================================================
--- trunk/boost/type_traits/is_enum.hpp (original)
+++ trunk/boost/type_traits/is_enum.hpp 2008-04-03 12:41:43 EDT (Thu, 03 Apr 2008)
@@ -11,6 +11,8 @@
#ifndef BOOST_TT_IS_ENUM_HPP_INCLUDED
#define BOOST_TT_IS_ENUM_HPP_INCLUDED
+#include <boost/type_traits/intrinsics.hpp>
+#ifndef BOOST_IS_ENUM
#include <boost/type_traits/add_reference.hpp>
#include <boost/type_traits/is_arithmetic.hpp>
#include <boost/type_traits/is_reference.hpp>
@@ -24,13 +26,14 @@
# include <boost/type_traits/is_class.hpp>
# include <boost/type_traits/is_union.hpp>
#endif
-
+#endif
// should be the last #include
#include <boost/type_traits/detail/bool_trait_def.hpp>
namespace boost {
+#ifndef BOOST_IS_ENUM
#if !(defined(__BORLANDC__) && (__BORLANDC__ <= 0x551))
namespace detail {
@@ -173,6 +176,12 @@
#endif
+#else // BOOST_IS_ENUM
+
+BOOST_TT_AUX_BOOL_TRAIT_DEF1(is_enum,T,BOOST_IS_ENUM(T))
+
+#endif
+
} // namespace boost
#include <boost/type_traits/detail/bool_trait_undef.hpp>
Modified: trunk/boost/type_traits/is_polymorphic.hpp
==============================================================================
--- trunk/boost/type_traits/is_polymorphic.hpp (original)
+++ trunk/boost/type_traits/is_polymorphic.hpp 2008-04-03 12:41:43 EDT (Thu, 03 Apr 2008)
@@ -8,13 +8,19 @@
#ifndef BOOST_TT_IS_POLYMORPHIC_HPP
#define BOOST_TT_IS_POLYMORPHIC_HPP
+#include <boost/type_traits/intrinsics.hpp>
+#ifndef BOOST_IS_POLYMORPHIC
#include <boost/type_traits/is_class.hpp>
#include <boost/type_traits/remove_cv.hpp>
+#endif
// should be the last #include
#include <boost/type_traits/detail/bool_trait_def.hpp>
#include <boost/detail/workaround.hpp>
namespace boost{
+
+#ifndef BOOST_IS_POLYMORPHIC
+
namespace detail{
template <class T>
@@ -95,6 +101,12 @@
BOOST_TT_AUX_BOOL_TRAIT_DEF1(is_polymorphic,T,::boost::detail::is_polymorphic_imp<T>::value)
+#else // BOOST_IS_POLYMORPHIC
+
+BOOST_TT_AUX_BOOL_TRAIT_DEF1(is_polymorphic,T,BOOST_IS_POLYMORPHIC(T))
+
+#endif
+
} // namespace boost
#include <boost/type_traits/detail/bool_trait_undef.hpp>
Modified: trunk/libs/type_traits/test/check_integral_constant.hpp
==============================================================================
--- trunk/libs/type_traits/test/check_integral_constant.hpp (original)
+++ trunk/libs/type_traits/test/check_integral_constant.hpp 2008-04-03 12:41:43 EDT (Thu, 03 Apr 2008)
@@ -59,10 +59,16 @@
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, "<note>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 << ")</note>" )
+ {\
+ BOOST_WARN_MESSAGE(false, "<note>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 << ")</note>" );\
+ }\
+ }
}//detail
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk