From 355e575498f39ef0521791cf3e8b2578f2fbb9c7 Mon Sep 17 00:00:00 2001 From: John Maddock Date: Tue, 3 Oct 2000 11:47:24 +0000 Subject: [PATCH] More VC6 fixes for compressed_pair and type_traits. [SVN r7895] --- include/boost/detail/ob_type_traits.hpp | 96 ++++++++++++++++++++++--- include/boost/detail/type_traits.hpp | 22 ++++++ 2 files changed, 110 insertions(+), 8 deletions(-) diff --git a/include/boost/detail/ob_type_traits.hpp b/include/boost/detail/ob_type_traits.hpp index b579630..f535f37 100644 --- a/include/boost/detail/ob_type_traits.hpp +++ b/include/boost/detail/ob_type_traits.hpp @@ -10,6 +10,8 @@ // support partial specialisation. (C) John Maddock 2000 /* Release notes: + 03 Oct 2000: + Added more fixes to is_pointer and is_array (JM). 01st October 2000: Fixed is_pointer, is_reference, is_const, is_volatile, is_same, is_member_pointer using ideas suggested from "Generic: Mappings between Types and Values" @@ -122,13 +124,16 @@ namespace detail{ no_result is_same_helper(...); } +template struct is_reference; template struct is_same { private: static T t; static U u; public: - enum{ value = (sizeof(detail::yes_result) == sizeof(detail::is_same_helper(&t,&u))) }; + enum{ value = (sizeof(detail::yes_result) == sizeof(detail::is_same_helper(&t,&u))) + && (is_reference::value == is_reference::value) + && (sizeof(T) == sizeof(U)) }; }; template struct is_void{ enum{ value = false }; }; @@ -253,22 +258,31 @@ template struct is_fundamental //* is a type T an array - is_array namespace detail{ + struct pointer_helper + { + pointer_helper(const volatile void*); + }; + yes_result is_pointer_helper(pointer_helper); + double is_pointer_helper(...); template - yes_result is_array_helper(const volatile T*, const volatile T*); - double is_array_helper(...); + yes_result is_pointer_helper3(T (*)(void)); + template + yes_result is_pointer_helper3(T (*)(A1)); + template + yes_result is_pointer_helper3(T (*)(A1, A2)); + double is_pointer_helper3(...); } template struct is_array { private: static T t; public: - enum{ value = (1 == sizeof(detail::is_array_helper(t, &t)))}; + enum{ value = (1 == sizeof(detail::is_pointer_helper(t))) + && (sizeof(T) != sizeof(void*)) }; }; //* is a type T a pointer type (including function pointers) - is_pointer namespace detail{ - yes_result is_pointer_helper(const volatile void*const volatile); - double is_pointer_helper(...); } template struct is_pointer @@ -276,9 +290,11 @@ template struct is_pointer private: static T t; public: - enum{ value = !is_const::value + enum{ value = (!is_const::value && !is_volatile::value - && (1 == sizeof(detail::is_pointer_helper(t)))}; + && (sizeof(T) == sizeof(void*)) + && (1 == sizeof(detail::is_pointer_helper(t)))) + || (1 == sizeof(detail::is_pointer_helper3(t))) }; }; # ifdef BOOST_MSVC @@ -438,8 +454,72 @@ public: }; //*? is type T an empty composite type (allows cv-qual) +#if defined(BOOST_MSVC6_MEMBER_TEMPLATES) || !defined(BOOST_NO_MEMBER_TEMPLATES) + +namespace detail{ + +template +struct empty_helper_t1 : public T +{ + int i[256]; +}; +struct empty_helper_t2 { int i[256]; }; + +template +struct empty_helper_base +{ + enum{ value = (sizeof(empty_helper_t1) == sizeof(empty_helper_t2)) }; +}; + +template +struct empty_helper_nonbase +{ + enum{ value = false }; +}; + +template +struct empty_helper_chooser +{ + template + struct rebind + { + typedef empty_helper_nonbase type; + }; +}; + +template <> +struct empty_helper_chooser +{ + template + struct rebind + { + typedef empty_helper_base type; + }; +}; + +} // namespace detail + +template +struct is_empty +{ +private: + typedef detail::empty_helper_chooser< + !is_convertible::value + && !is_convertible::value + && !is_pointer::value + && !is_member_pointer::value + && !is_array::value + && !is_convertible::value> chooser; + typedef typename chooser::template rebind bound_type; + typedef typename bound_type::type eh_type; +public: + enum{ value = eh_type::value || BOOST_IS_EMPTY(T) }; +}; + +#else template struct is_empty { enum{ value = BOOST_IS_EMPTY(T) }; }; +#endif //*? T has trivial default constructor (allows cv-qual) template struct has_trivial_constructor diff --git a/include/boost/detail/type_traits.hpp b/include/boost/detail/type_traits.hpp index e507bfb..9b45ca2 100644 --- a/include/boost/detail/type_traits.hpp +++ b/include/boost/detail/type_traits.hpp @@ -10,6 +10,8 @@ // see libs/utility/type_traits.htm /* Release notes: + 03 Oct 2000: + Added gcc specific fixes for memeber pointers (JM). 31st July 2000: Added is_convertable, alignment_of, modified is_empty. 23rd July 2000: @@ -330,6 +332,17 @@ template struct is_array //* is a type T a pointer type (including function pointers) - is_pointer template struct is_pointer { static const bool value = false; }; template struct is_pointer { static const bool value = true; }; +#ifdef __GNUC__ +// gcc workarounds: these partial specialisations should not be needed: +template struct is_pointer +{ static const bool value = false; }; +template struct is_pointer +{ static const bool value = false; }; +template struct is_pointer +{ static const bool value = false; }; +template struct is_pointer +{ static const bool value = false; }; +#endif //* is a type T a reference type - is_reference template struct is_reference { static const bool value = false; }; @@ -367,6 +380,15 @@ template struct is_member_pointer { static const bool value = false; }; template struct is_member_pointer { static const bool value = true; }; +#ifdef __GNUC__ +// gcc workaround (JM 02 Oct 2000) +template struct is_member_pointer +{ static const bool value = true; }; +template struct is_member_pointer +{ static const bool value = true; }; +template struct is_member_pointer +{ static const bool value = true; }; +#endif //* is type T an object type (allows cv-qual) template struct is_object