diff options
author | paolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4> | 2005-03-05 00:22:48 +0000 |
---|---|---|
committer | paolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4> | 2005-03-05 00:22:48 +0000 |
commit | 84759018ea73f294828768299cbac924870794af (patch) | |
tree | efce5374a01e36396abcf2be3ed9384e24f5efb6 /libstdc++-v3/include | |
parent | 39ffba169c09a430c31e8094a17a34cf654a318a (diff) | |
download | gcc-84759018ea73f294828768299cbac924870794af.tar.gz |
2005-03-04 Paolo Carlini <pcarlini@suse.de>
* include/tr1/type_traits: Add is_base_of.
* testsuite/tr1/4_metaprogramming/relationships_between_types/
is_base_of/is_base_of.cc: New.
* testsuite/tr1/4_metaprogramming/relationships_between_types/
is_base_of/typedefs.cc: Likewise.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@95911 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libstdc++-v3/include')
-rw-r--r-- | libstdc++-v3/include/tr1/type_traits | 39 |
1 files changed, 38 insertions, 1 deletions
diff --git a/libstdc++-v3/include/tr1/type_traits b/libstdc++-v3/include/tr1/type_traits index 37415881c7a..afdea0c2ad2 100644 --- a/libstdc++-v3/include/tr1/type_traits +++ b/libstdc++-v3/include/tr1/type_traits @@ -42,7 +42,7 @@ namespace std { namespace tr1 { - // For use in is_enum, is_abstract and elsewhere. + // For use in __conv_helper, is_abstract and elsewhere. struct __sfinae_types { typedef char __one; @@ -456,6 +456,43 @@ namespace tr1 struct is_same<_Tp, _Tp> : public true_type { }; + // See Daveed Vandevoorde explanation in http://tinyurl.com/502f. + // Also see Rani Sharoni in http://tinyurl.com/6jvyq. + template<typename _Base, typename _Derived, + bool = (!__is_union_or_class<_Base>::value + || !__is_union_or_class<_Derived>::value + || is_same<_Base, _Derived>::value)> + struct __is_base_of_helper + : public __sfinae_types + { + private: + typedef typename remove_cv<_Base>::type _NoCv_Base; + typedef typename remove_cv<_Derived>::type _NoCv_Derived; + + template<typename _Up> + static __one __test(_NoCv_Derived&, _Up); + static __two __test(_NoCv_Base&, int); + + struct _Conv + { + operator _NoCv_Derived&(); + operator _NoCv_Base&() const; + }; + + public: + static const bool __value = sizeof(__test(_Conv(), 0)) == 1; + }; + + template<typename _Base, typename _Derived> + struct __is_base_of_helper<_Base, _Derived, true> + { static const bool __value = is_same<_Base, _Derived>::value; }; + + template<typename _Base, typename _Derived> + struct is_base_of + : public integral_constant<bool, + __is_base_of_helper<_Base, _Derived>::__value> + { }; + template<typename _Tp> struct __is_int_or_cref { |