From 111d40e909ce5cf507ce7d4aa81f35d947f03fe0 Mon Sep 17 00:00:00 2001 From: John Maddock Date: Sun, 25 Mar 2001 10:34:35 +0000 Subject: [PATCH] added add_const/add_volatile/is_function Fixed is_const/is_volatile to work with reference types Fixed is_object to work with function types. Fixed is_enum/is_empty to work with incomplete/abstract/function types [SVN r9640] --- .../boost/type_traits/composite_traits.hpp | 241 +++++++++++++++--- include/boost/type_traits/cv_traits.hpp | 58 +++++ include/boost/type_traits/function_traits.hpp | 156 ++++++++++++ include/boost/type_traits/object_traits.hpp | 27 +- include/boost/type_traits/same_traits.hpp | 6 +- .../boost/type_traits/transform_traits.hpp | 13 + .../boost/type_traits/type_traits_test.hpp | 12 + 7 files changed, 472 insertions(+), 41 deletions(-) create mode 100644 include/boost/type_traits/function_traits.hpp diff --git a/include/boost/type_traits/composite_traits.hpp b/include/boost/type_traits/composite_traits.hpp index c5dfe8f..3672cd9 100644 --- a/include/boost/type_traits/composite_traits.hpp +++ b/include/boost/type_traits/composite_traits.hpp @@ -17,6 +17,11 @@ // All rights reserved.). // Fixes for is_array are based on a newgroup posting by Jonathan Lundquist. +// +// Revision History: +// 21st March 2001: +// Fixed is_enum so that it works with incomplete types. + #ifndef BOOST_COMPOSITE_TYPE_TRAITS_HPP #define BOOST_COMPOSITE_TYPE_TRAITS_HPP @@ -35,6 +40,9 @@ #ifndef BOOST_ARITHMETIC_TYPE_TRAITS_HPP #include #endif +#ifndef BOOST_TRANSFORM_TRAITS_HPP +#include +#endif namespace boost{ @@ -62,15 +70,71 @@ namespace detail{ }; yes_type is_pointer_helper(pointer_helper); no_type is_pointer_helper(...); - template - yes_type is_pointer_helper3(T (*)(void)); - template - yes_type is_pointer_helper3(T (*)(A1)); - template - yes_type is_pointer_helper3(T (*)(A1, A2)); - template - yes_type is_pointer_helper3(T (*)(A1, A2, A3)); - no_type is_pointer_helper3(...); + +::boost::type_traits::no_type is_function_tester(...); +template +::boost::type_traits::yes_type is_function_tester(R (*)(void)); +template +::boost::type_traits::yes_type is_function_tester(R (*)(A0)); +template +::boost::type_traits::yes_type is_function_tester(R (*)(A0, A1)); +template +::boost::type_traits::yes_type is_function_tester(R (*)(A0, A1, A2)); +template +::boost::type_traits::yes_type is_function_tester(R (*)(A0, A1, A2, A3)); +template +::boost::type_traits::yes_type is_function_tester(R (*)(A0, A1, A2, A3, A4)); +template +::boost::type_traits::yes_type is_function_tester(R (*)(A0, A1, A2, A3, A4, A5)); +template +::boost::type_traits::yes_type is_function_tester(R (*)(A0, A1, A2, A3, A4, A5, A6)); +template +::boost::type_traits::yes_type is_function_tester(R (*)(A0, A1, A2, A3, A4, A5, A6, A7)); +template +::boost::type_traits::yes_type is_function_tester(R (*)(A0, A1, A2, A3, A4, A5, A6, A7, A8)); +template +::boost::type_traits::yes_type is_function_tester(R (*)(A0, A1, A2, A3, A4, A5, A6, A7, A8, A9)); +template +::boost::type_traits::yes_type is_function_tester(R (*)(A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10)); +template +::boost::type_traits::yes_type is_function_tester(R (*)(A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11)); +template +::boost::type_traits::yes_type is_function_tester(R (*)(A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12)); +template +::boost::type_traits::yes_type is_function_tester(R (*)(A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13)); +template +::boost::type_traits::yes_type is_function_tester(R (*)(A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14)); +template +::boost::type_traits::yes_type is_function_tester(R (*)(A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15)); +template +::boost::type_traits::yes_type is_function_tester(R (*)(A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16)); +template +::boost::type_traits::yes_type is_function_tester(R (*)(A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17)); +template +::boost::type_traits::yes_type is_function_tester(R (*)(A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18)); +template +::boost::type_traits::yes_type is_function_tester(R (*)(A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, A19)); +template +::boost::type_traits::yes_type is_function_tester(R (*)(A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, A19, A20)); +template +::boost::type_traits::yes_type is_function_tester(R (*)(A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, A19, A20, A21)); +template +::boost::type_traits::yes_type is_function_tester(R (*)(A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, A19, A20, A21, A22)); +template +::boost::type_traits::yes_type is_function_tester(R (*)(A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, A19, A20, A21, A22, A23)); +template +::boost::type_traits::yes_type is_function_tester(R (*)(A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, A19, A20, A21, A22, A23, A24)); +template +::boost::type_traits::yes_type is_function_tester(R (*)(A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, A19, A20, A21, A22, A23, A24, A25)); +template +::boost::type_traits::yes_type is_function_tester(R (*)(A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, A19, A20, A21, A22, A23, A24, A25, A26)); +template +::boost::type_traits::yes_type is_function_tester(R (*)(A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, A19, A20, A21, A22, A23, A24, A25, A26, A27)); +template +::boost::type_traits::yes_type is_function_tester(R (*)(A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, A19, A20, A21, A22, A23, A24, A25, A26, A27, A28)); +template +::boost::type_traits::yes_type is_function_tester(R (*)(A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, A19, A20, A21, A22, A23, A24, A25, A26, A27, A28, A29)); + yes_type is_array_helper(const volatile void*, const volatile void*); template @@ -89,7 +153,7 @@ public: ::boost::type_traits::ice_not< ::boost::is_reference::value>::value, ::boost::type_traits::ice_not< - (1 == sizeof(detail::is_pointer_helper3(t)))>::value + (1 == sizeof(detail::is_function_tester(t)))>::value >::value)); }; template <> @@ -154,7 +218,7 @@ public: >::value, (::boost::type_traits::ice_or< (1 == sizeof(detail::is_pointer_helper(t))), - (1 == sizeof(detail::is_pointer_helper3(t))) + (1 == sizeof(detail::is_function_tester(t))) >::value) >::value ) ); }; @@ -208,7 +272,7 @@ template struct is_reference # ifdef BOOST_MSVC # pragma warning(push) # pragma warning(disable: 4181) -# endif // BOOST_MSVC +#endif // BOOST_MSVC template struct is_reference { private: @@ -268,11 +332,14 @@ struct int_convertible #ifndef __BORLANDC__ template struct is_enum { +private: + typedef typename ::boost::add_reference::type r_type; +public: BOOST_STATIC_CONSTANT(bool, value = (::boost::type_traits::ice_and< ::boost::type_traits::ice_not< ::boost::is_arithmetic::value>::value, ::boost::type_traits::ice_not< ::boost::is_reference::value>::value, - ::boost::is_convertible::value + ::boost::is_convertible::value >::value)); }; #else // __BORLANDC__ @@ -298,35 +365,131 @@ template struct is_member_pointer { BOOST_STATIC_CONSTANT(bool, value = true); }; #ifdef __GNUC__ // gcc workaround (JM 02 Oct 2000) -template struct is_member_pointer -{ BOOST_STATIC_CONSTANT(bool, value = true); }; -template struct is_member_pointer -{ BOOST_STATIC_CONSTANT(bool, value = true); }; -template struct is_member_pointer -{ BOOST_STATIC_CONSTANT(bool, value = true); }; -template struct is_member_pointer -{ BOOST_STATIC_CONSTANT(bool, value = true); }; -template struct is_member_pointer -{ BOOST_STATIC_CONSTANT(bool, value = true); }; -template struct is_member_pointer -{ BOOST_STATIC_CONSTANT(bool, value = true); }; +template +struct is_member_pointer{ BOOST_STATIC_CONSTANT(bool, value = true); }; +template +struct is_member_pointer{ BOOST_STATIC_CONSTANT(bool, value = true); }; +template +struct is_member_pointer{ BOOST_STATIC_CONSTANT(bool, value = true); }; +template +struct is_member_pointer{ BOOST_STATIC_CONSTANT(bool, value = true); }; +template +struct is_member_pointer{ BOOST_STATIC_CONSTANT(bool, value = true); }; +template +struct is_member_pointer{ BOOST_STATIC_CONSTANT(bool, value = true); }; +template +struct is_member_pointer{ BOOST_STATIC_CONSTANT(bool, value = true); }; +template +struct is_member_pointer{ BOOST_STATIC_CONSTANT(bool, value = true); }; +template +struct is_member_pointer{ BOOST_STATIC_CONSTANT(bool, value = true); }; +template +struct is_member_pointer{ BOOST_STATIC_CONSTANT(bool, value = true); }; +template +struct is_member_pointer{ BOOST_STATIC_CONSTANT(bool, value = true); }; +template +struct is_member_pointer{ BOOST_STATIC_CONSTANT(bool, value = true); }; +template +struct is_member_pointer{ BOOST_STATIC_CONSTANT(bool, value = true); }; +template +struct is_member_pointer{ BOOST_STATIC_CONSTANT(bool, value = true); }; +template +struct is_member_pointer{ BOOST_STATIC_CONSTANT(bool, value = true); }; +template +struct is_member_pointer{ BOOST_STATIC_CONSTANT(bool, value = true); }; +template +struct is_member_pointer{ BOOST_STATIC_CONSTANT(bool, value = true); }; +template +struct is_member_pointer{ BOOST_STATIC_CONSTANT(bool, value = true); }; +template +struct is_member_pointer{ BOOST_STATIC_CONSTANT(bool, value = true); }; +template +struct is_member_pointer{ BOOST_STATIC_CONSTANT(bool, value = true); }; +template +struct is_member_pointer{ BOOST_STATIC_CONSTANT(bool, value = true); }; +template +struct is_member_pointer{ BOOST_STATIC_CONSTANT(bool, value = true); }; +template +struct is_member_pointer{ BOOST_STATIC_CONSTANT(bool, value = true); }; +template +struct is_member_pointer{ BOOST_STATIC_CONSTANT(bool, value = true); }; +template +struct is_member_pointer{ BOOST_STATIC_CONSTANT(bool, value = true); }; +template +struct is_member_pointer{ BOOST_STATIC_CONSTANT(bool, value = true); }; +template +struct is_member_pointer{ BOOST_STATIC_CONSTANT(bool, value = true); }; +template +struct is_member_pointer{ BOOST_STATIC_CONSTANT(bool, value = true); }; +template +struct is_member_pointer{ BOOST_STATIC_CONSTANT(bool, value = true); }; +template +struct is_member_pointer{ BOOST_STATIC_CONSTANT(bool, value = true); }; #endif #else namespace detail{ - template - yes_type is_member_pointer_helper(T (U::*)); - template - yes_type is_member_pointer_helper(T (U::*)(void)); - template - yes_type is_member_pointer_helper(T (U::*)(A1)); - template - yes_type is_member_pointer_helper(T (U::*)(A1, A2)); - template - yes_type is_member_pointer_helper(T (U::*)(A1, A2, A3)); - template - yes_type is_member_pointer_helper(T (U::*)(A1, A2, A3, A4)); - template - yes_type is_member_pointer_helper(T (U::*)(A1, A2, A3, A4, A5)); +template +::boost::type_traits::yes_type is_member_pointer_helper(R (T::*)(void)); +template +::boost::type_traits::yes_type is_member_pointer_helper(R (T::*)(A0)); +template +::boost::type_traits::yes_type is_member_pointer_helper(R (T::*)(A0, A1)); +template +::boost::type_traits::yes_type is_member_pointer_helper(R (T::*)(A0, A1, A2)); +template +::boost::type_traits::yes_type is_member_pointer_helper(R (T::*)(A0, A1, A2, A3)); +template +::boost::type_traits::yes_type is_member_pointer_helper(R (T::*)(A0, A1, A2, A3, A4)); +template +::boost::type_traits::yes_type is_member_pointer_helper(R (T::*)(A0, A1, A2, A3, A4, A5)); +template +::boost::type_traits::yes_type is_member_pointer_helper(R (T::*)(A0, A1, A2, A3, A4, A5, A6)); +template +::boost::type_traits::yes_type is_member_pointer_helper(R (T::*)(A0, A1, A2, A3, A4, A5, A6, A7)); +template +::boost::type_traits::yes_type is_member_pointer_helper(R (T::*)(A0, A1, A2, A3, A4, A5, A6, A7, A8)); +template +::boost::type_traits::yes_type is_member_pointer_helper(R (T::*)(A0, A1, A2, A3, A4, A5, A6, A7, A8, A9)); +template +::boost::type_traits::yes_type is_member_pointer_helper(R (T::*)(A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10)); +template +::boost::type_traits::yes_type is_member_pointer_helper(R (T::*)(A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11)); +template +::boost::type_traits::yes_type is_member_pointer_helper(R (T::*)(A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12)); +template +::boost::type_traits::yes_type is_member_pointer_helper(R (T::*)(A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13)); +template +::boost::type_traits::yes_type is_member_pointer_helper(R (T::*)(A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14)); +template +::boost::type_traits::yes_type is_member_pointer_helper(R (T::*)(A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15)); +template +::boost::type_traits::yes_type is_member_pointer_helper(R (T::*)(A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16)); +template +::boost::type_traits::yes_type is_member_pointer_helper(R (T::*)(A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17)); +template +::boost::type_traits::yes_type is_member_pointer_helper(R (T::*)(A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18)); +template +::boost::type_traits::yes_type is_member_pointer_helper(R (T::*)(A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, A19)); +template +::boost::type_traits::yes_type is_member_pointer_helper(R (T::*)(A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, A19, A20)); +template +::boost::type_traits::yes_type is_member_pointer_helper(R (T::*)(A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, A19, A20, A21)); +template +::boost::type_traits::yes_type is_member_pointer_helper(R (T::*)(A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, A19, A20, A21, A22)); +template +::boost::type_traits::yes_type is_member_pointer_helper(R (T::*)(A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, A19, A20, A21, A22, A23)); +template +::boost::type_traits::yes_type is_member_pointer_helper(R (T::*)(A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, A19, A20, A21, A22, A23, A24)); +template +::boost::type_traits::yes_type is_member_pointer_helper(R (T::*)(A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, A19, A20, A21, A22, A23, A24, A25)); +template +::boost::type_traits::yes_type is_member_pointer_helper(R (T::*)(A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, A19, A20, A21, A22, A23, A24, A25, A26)); +template +::boost::type_traits::yes_type is_member_pointer_helper(R (T::*)(A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, A19, A20, A21, A22, A23, A24, A25, A26, A27)); +template +::boost::type_traits::yes_type is_member_pointer_helper(R (T::*)(A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, A19, A20, A21, A22, A23, A24, A25, A26, A27, A28)); +template +::boost::type_traits::yes_type is_member_pointer_helper(R (T::*)(A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, A19, A20, A21, A22, A23, A24, A25, A26, A27, A28, A29)); no_type is_member_pointer_helper(...); } template diff --git a/include/boost/type_traits/cv_traits.hpp b/include/boost/type_traits/cv_traits.hpp index fe62ec2..5878828 100644 --- a/include/boost/type_traits/cv_traits.hpp +++ b/include/boost/type_traits/cv_traits.hpp @@ -9,6 +9,9 @@ // defines traits classes for cv-qualified types: // is_const, is_volatile, remove_const, remove_volatile, remove_cv. // +// Revision History: +// 24th March 2001: +// Fixed is_const/is_volatile so that they work with reference types #ifndef BOOST_CV_TYPE_TRAITS_HPP #define BOOST_CV_TYPE_TRAITS_HPP @@ -125,6 +128,20 @@ struct is_const { BOOST_STATIC_CONSTANT(bool, value = detail::cv_traits_imp::is_const); }; +template struct is_const +{ BOOST_STATIC_CONSTANT(bool, value = false); }; +#if defined(__BORLANDC__) +// these are illegal specialisations; cv-qualifies applied to +// references have no effect according to [8.3.2p1], +// C++ Builder requires them though as it treats cv-qualified +// references as distinct types... +template struct is_const +{ BOOST_STATIC_CONSTANT(bool, value = false); }; +template struct is_const +{ BOOST_STATIC_CONSTANT(bool, value = false); }; +template struct is_const +{ BOOST_STATIC_CONSTANT(bool, value = false); }; +#endif //* is a type T declared volatile - is_volatile template @@ -132,6 +149,20 @@ struct is_volatile { BOOST_STATIC_CONSTANT(bool, value = detail::cv_traits_imp::is_volatile); }; +template struct is_volatile +{ BOOST_STATIC_CONSTANT(bool, value = false); }; +#if defined(__BORLANDC__) +// these are illegal specialisations; cv-qualifies applied to +// references have no effect according to [8.3.2p1], +// C++ Builder requires them though as it treats cv-qualified +// references as distinct types... +template struct is_volatile +{ BOOST_STATIC_CONSTANT(bool, value = false); }; +template struct is_volatile +{ BOOST_STATIC_CONSTANT(bool, value = false); }; +template struct is_volatile +{ BOOST_STATIC_CONSTANT(bool, value = false); }; +#endif #else // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION // The following three don't work: @@ -213,9 +244,36 @@ struct is_volatile #endif #endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION + +// * convert a type T to const type - add_const +// this is not required since the result is always +// the same as "T const", but it does suppress warnings +// from some compilers: +template +struct add_const +{ + typedef T const type; +}; +// * convert a type T to volatile type - add_volatile +// this is not required since the result is always +// the same as "T volatile", but it does suppress warnings +// from some compilers: +template +struct add_volatile +{ + typedef T volatile type; +}; +#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION +template +struct add_const{ typedef T& type; }; +template +struct add_volatile{ typedef T& type; }; +#endif + } // namespace boost #endif // BOOST_CV_TYPE_TRAITS_HPP + diff --git a/include/boost/type_traits/function_traits.hpp b/include/boost/type_traits/function_traits.hpp new file mode 100644 index 0000000..0440429 --- /dev/null +++ b/include/boost/type_traits/function_traits.hpp @@ -0,0 +1,156 @@ + +// Copyright (C) 2000 John Maddock (john_maddock@compuserve.com) +// +// Permission to copy and use this software is granted, +// provided this copyright notice appears in all copies. +// Permission to modify the code and to distribute modified code is granted, +// provided this copyright notice appears in all copies, and a notice +// that the code was modified is included with the copyright notice. +// +// This software is provided "as is" without express or implied warranty, +// and with no claim as to its suitability for any purpose. + +#ifndef BOOST_FUNCTION_TYPE_TRAITS_HPP +#define BOOST_FUNCTION_TYPE_TRAITS_HPP + +#ifndef BOOST_ICE_TYPE_TRAITS_HPP +#include +#endif +#ifndef BOOST_FWD_TYPE_TRAITS_HPP +#include +#endif +#ifndef BOOST_COMPOSITE_TYPE_TRAITS_HPP +#include +#endif +// +// is a type a function? +// +namespace boost{ +namespace detail{ + +#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION + +template +struct is_function_helper_base{ BOOST_STATIC_CONSTANT(bool, value = false); }; +template +struct is_function_helper_base{ BOOST_STATIC_CONSTANT(bool, value = true); }; +template +struct is_function_helper_base{ BOOST_STATIC_CONSTANT(bool, value = true); }; +template +struct is_function_helper_base{ BOOST_STATIC_CONSTANT(bool, value = true); }; +template +struct is_function_helper_base{ BOOST_STATIC_CONSTANT(bool, value = true); }; +template +struct is_function_helper_base{ BOOST_STATIC_CONSTANT(bool, value = true); }; +template +struct is_function_helper_base{ BOOST_STATIC_CONSTANT(bool, value = true); }; +template +struct is_function_helper_base{ BOOST_STATIC_CONSTANT(bool, value = true); }; +template +struct is_function_helper_base{ BOOST_STATIC_CONSTANT(bool, value = true); }; +template +struct is_function_helper_base{ BOOST_STATIC_CONSTANT(bool, value = true); }; +template +struct is_function_helper_base{ BOOST_STATIC_CONSTANT(bool, value = true); }; +template +struct is_function_helper_base{ BOOST_STATIC_CONSTANT(bool, value = true); }; +template +struct is_function_helper_base{ BOOST_STATIC_CONSTANT(bool, value = true); }; +template +struct is_function_helper_base{ BOOST_STATIC_CONSTANT(bool, value = true); }; +template +struct is_function_helper_base{ BOOST_STATIC_CONSTANT(bool, value = true); }; +template +struct is_function_helper_base{ BOOST_STATIC_CONSTANT(bool, value = true); }; +template +struct is_function_helper_base{ BOOST_STATIC_CONSTANT(bool, value = true); }; +template +struct is_function_helper_base{ BOOST_STATIC_CONSTANT(bool, value = true); }; +template +struct is_function_helper_base{ BOOST_STATIC_CONSTANT(bool, value = true); }; +template +struct is_function_helper_base{ BOOST_STATIC_CONSTANT(bool, value = true); }; +template +struct is_function_helper_base{ BOOST_STATIC_CONSTANT(bool, value = true); }; +template +struct is_function_helper_base{ BOOST_STATIC_CONSTANT(bool, value = true); }; +template +struct is_function_helper_base{ BOOST_STATIC_CONSTANT(bool, value = true); }; +template +struct is_function_helper_base{ BOOST_STATIC_CONSTANT(bool, value = true); }; +template +struct is_function_helper_base{ BOOST_STATIC_CONSTANT(bool, value = true); }; +template +struct is_function_helper_base{ BOOST_STATIC_CONSTANT(bool, value = true); }; +template +struct is_function_helper_base{ BOOST_STATIC_CONSTANT(bool, value = true); }; +template +struct is_function_helper_base{ BOOST_STATIC_CONSTANT(bool, value = true); }; +template +struct is_function_helper_base{ BOOST_STATIC_CONSTANT(bool, value = true); }; +template +struct is_function_helper_base{ BOOST_STATIC_CONSTANT(bool, value = true); }; +template +struct is_function_helper_base{ BOOST_STATIC_CONSTANT(bool, value = true); }; + +template +struct is_function_helper : is_function_helper_base{}; + +#else + +template +struct is_function_helper +{ + static T* t; + BOOST_STATIC_CONSTANT(bool, value = sizeof(is_function_tester(t)) == sizeof(::boost::type_traits::yes_type)); +}; + +#endif + +template +struct is_function_ref_helper +{ + BOOST_STATIC_CONSTANT(bool, value = false); +}; + + +template +struct is_function_chooser +{ + template + struct rebind + { + typedef is_function_helper type; + }; +}; +template <> +struct is_function_chooser +{ + template + struct rebind + { + typedef is_function_ref_helper type; + }; +}; +} // namespace detail + +template +struct is_function +{ +private: +#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) + typedef typename detail::is_function_chooser< ::boost::is_reference::value>::template rebind binder; + typedef typename binder::type type; +#else + // without partial specialistaion we can't use is_reference on + // function types, that leaves this template broken in the case that + // T is a reference: + typedef detail::is_function_helper type; +#endif +public: + BOOST_STATIC_CONSTANT(bool, value = type::value); +}; + +} // boost + +#endif // BOOST_FUNCTION_TYPE_TRAITS_HPP \ No newline at end of file diff --git a/include/boost/type_traits/object_traits.hpp b/include/boost/type_traits/object_traits.hpp index 7deca0e..5202d98 100644 --- a/include/boost/type_traits/object_traits.hpp +++ b/include/boost/type_traits/object_traits.hpp @@ -27,6 +27,9 @@ #ifndef BOOST_ARITHMETIC_TYPE_TRAITS_HPP #include #endif +#ifndef BOOST_FUNCTION_TYPE_TRAITS_HPP +#include +#endif namespace boost{ @@ -38,11 +41,20 @@ namespace boost{ template struct is_object { +#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION + BOOST_STATIC_CONSTANT(bool, value = + (::boost::type_traits::ice_and< + ::boost::type_traits::ice_not< ::boost::is_reference::value>::value, + ::boost::type_traits::ice_not< ::boost::is_void::value>::value, + ::boost::type_traits::ice_not< ::boost::is_function::value>::value + >::value)); +#else BOOST_STATIC_CONSTANT(bool, value = (::boost::type_traits::ice_and< ::boost::type_traits::ice_not< ::boost::is_reference::value>::value, ::boost::type_traits::ice_not< ::boost::is_void::value>::value >::value)); +#endif }; /********************************************** @@ -70,6 +82,17 @@ struct is_scalar template struct is_class { +#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION + BOOST_STATIC_CONSTANT(bool, value = + (::boost::type_traits::ice_and< + ::boost::type_traits::ice_not< ::boost::is_union::value >::value, + ::boost::type_traits::ice_not< ::boost::is_scalar::value >::value, + ::boost::type_traits::ice_not< ::boost::is_array::value >::value, + ::boost::type_traits::ice_not< ::boost::is_reference::value>::value, + ::boost::type_traits::ice_not< ::boost::is_void::value >::value, + ::boost::type_traits::ice_not< ::boost::is_function::value >::value + >::value)); +#else BOOST_STATIC_CONSTANT(bool, value = (::boost::type_traits::ice_and< ::boost::type_traits::ice_not< ::boost::is_union::value >::value, @@ -78,6 +101,7 @@ struct is_class ::boost::type_traits::ice_not< ::boost::is_reference::value>::value, ::boost::type_traits::ice_not< ::boost::is_void::value >::value >::value)); +#endif }; /********************************************** @@ -222,12 +246,13 @@ struct is_empty { private: typedef typename remove_cv::type cvt; + typedef typename add_reference::type r_type; public: BOOST_STATIC_CONSTANT(bool, value = (::boost::type_traits::ice_or< ::boost::detail::empty_helper::value , - ::boost::is_convertible::value + ::boost::is_convertible< r_type,int>::value >::value, BOOST_IS_EMPTY(cvt) >::value)); diff --git a/include/boost/type_traits/same_traits.hpp b/include/boost/type_traits/same_traits.hpp index 5719068..5c9fef1 100644 --- a/include/boost/type_traits/same_traits.hpp +++ b/include/boost/type_traits/same_traits.hpp @@ -44,7 +44,11 @@ struct is_same #else // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION #ifdef BOOST_MSVC - +// +// the following VC6 specific implementation is *NOT* legal +// C++, but has the advantage that it works for incomplete +// types. +// namespace detail{ template diff --git a/include/boost/type_traits/transform_traits.hpp b/include/boost/type_traits/transform_traits.hpp index 22821bc..ecdbb04 100644 --- a/include/boost/type_traits/transform_traits.hpp +++ b/include/boost/type_traits/transform_traits.hpp @@ -9,6 +9,9 @@ // defines traits classes for transforming one type to another: // remove_reference, add_reference, remove_bounds, remove_pointer. // +// Revision History: +// 21st March 2001 +// Added void specialisations to add_reference. #ifndef BOOST_TRANSFORM_TRAITS_HPP #define BOOST_TRANSFORM_TRAITS_HPP @@ -106,6 +109,16 @@ struct add_reference { typedef T& type; }; #endif +// +// these full specialisations are always required: +template <> struct add_reference{ typedef void type; }; +#ifndef BOOST_NO_CV_VOID_SPECIALIZATIONS +template <> struct add_reference{ typedef const volatile void type; }; +template <> struct add_reference{ typedef const void type; }; +template <> struct add_reference{ typedef volatile void type; }; +#endif + + /********************************************** * * remove_bounds diff --git a/include/boost/type_traits/type_traits_test.hpp b/include/boost/type_traits/type_traits_test.hpp index d4caa33..c3eef30 100644 --- a/include/boost/type_traits/type_traits_test.hpp +++ b/include/boost/type_traits/type_traits_test.hpp @@ -350,7 +350,19 @@ struct non_empty : boost::noncopyable { int i; }; +// +// abstract base classes: +struct test_abc1 +{ + virtual void foo() = 0; + virtual void foo2() = 0; +}; +struct test_abc2 +{ + virtual void foo() = 0; + virtual void foo2() = 0; +}; #endif // BOOST_TYPE_TRAITS_TEST_HPP