aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaolo Carlini <pcarlini@suse.de>2005-01-28 13:29:41 +0000
committerPaolo Carlini <paolo@gcc.gnu.org>2005-01-28 13:29:41 +0000
commitf8023b78462af97c3fe7a6b7786a9c19c82107d9 (patch)
tree7a291daf88e4bb4d119f8a3bdc61b8285d63b1a7
parent2aa3d033a12542ddbda510b855141b8fda74184f (diff)
downloadgcc-f8023b78462af97c3fe7a6b7786a9c19c82107d9.zip
gcc-f8023b78462af97c3fe7a6b7786a9c19c82107d9.tar.gz
gcc-f8023b78462af97c3fe7a6b7786a9c19c82107d9.tar.bz2
type_traits: Implement is_abstract, by exploiting the resolution of DR core/337.
2005-01-28 Paolo Carlini <pcarlini@suse.de> * include/tr1/type_traits: Implement is_abstract, by exploiting the resolution of DR core/337. * testsuite/testsuite_tr1.h: Add AbstractClass. * testsuite/tr1/4_metaprogramming/type_properties/is_abstract/ is_abstract.cc: New. * testsuite/tr1/4_metaprogramming/type_properties/is_abstract/ typedefs.cc: Likewise. * include/tr1/type_traits (is_function): Rewrite, use the conversion F& -> F* instead, thus avoiding problems with abstract classes. * testsuite/tr1/4_metaprogramming/primary_type_categories/ is_function/is_function.cc: Add a test for tricky AbstractClass. From-SVN: r94370
-rw-r--r--libstdc++-v3/ChangeLog15
-rw-r--r--libstdc++-v3/include/tr1/type_traits65
-rw-r--r--libstdc++-v3/testsuite/testsuite_tr1.h5
-rw-r--r--libstdc++-v3/testsuite/tr1/4_metaprogramming/primary_type_categories/is_function/is_function.cc4
-rw-r--r--libstdc++-v3/testsuite/tr1/4_metaprogramming/type_properties/is_abstract/is_abstract.cc49
-rw-r--r--libstdc++-v3/testsuite/tr1/4_metaprogramming/type_properties/is_abstract/typedefs.cc36
6 files changed, 151 insertions, 23 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index 2742f60..f9b1de5 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,3 +1,18 @@
+2005-01-28 Paolo Carlini <pcarlini@suse.de>
+
+ * include/tr1/type_traits: Implement is_abstract, by exploiting the
+ resolution of DR core/337.
+ * testsuite/testsuite_tr1.h: Add AbstractClass.
+ * testsuite/tr1/4_metaprogramming/type_properties/is_abstract/
+ is_abstract.cc: New.
+ * testsuite/tr1/4_metaprogramming/type_properties/is_abstract/
+ typedefs.cc: Likewise.
+
+ * include/tr1/type_traits (is_function): Rewrite, use the conversion
+ F& -> F* instead, thus avoiding problems with abstract classes.
+ * testsuite/tr1/4_metaprogramming/primary_type_categories/
+ is_function/is_function.cc: Add a test for tricky AbstractClass.
+
2005-01-26 Paolo Carlini <pcarlini@suse.de>
* include/ext/mt_allocator.h
diff --git a/libstdc++-v3/include/tr1/type_traits b/libstdc++-v3/include/tr1/type_traits
index 34c1c9f..d75e5df 100644
--- a/libstdc++-v3/include/tr1/type_traits
+++ b/libstdc++-v3/include/tr1/type_traits
@@ -33,13 +33,26 @@ namespace std
{
namespace tr1
{
- // For use in is_enum, is_function, and elsewhere.
+ // For use in is_enum, is_abstract and elsewhere.
struct __sfinae_types
{
typedef char __one;
typedef struct { char __arr[2]; } __two;
};
+ template<typename _From, typename _To>
+ struct __conv_helper
+ : public __sfinae_types
+ {
+ private:
+ static __one __test(_To);
+ static __two __test(...);
+ static _From __makeFrom();
+
+ public:
+ static const bool __value = sizeof(__test(__makeFrom())) == 1;
+ };
+
#define _DEFINE_SPEC_BODY(_Value) \
: public integral_constant<bool, _Value> { };
@@ -393,28 +406,13 @@ namespace tr1
struct is_enum
: public integral_constant<bool, __is_enum_helper<_Tp>::__value> { };
- template<typename _Tp, bool = (is_reference<_Tp>::value
- || is_void<_Tp>::value)>
- struct __is_function_helper
- : public __sfinae_types
- {
- private:
- template<typename>
- static __one __test(...);
- template<typename _Up>
- static __two __test(_Up(*)[1]);
-
- public:
- static const bool __value = sizeof(__test<_Tp>(0)) == 1;
- };
-
- template<typename _Tp>
- struct __is_function_helper<_Tp, true>
- { static const bool __value = false; };
-
template<typename _Tp>
struct is_function
- : public integral_constant<bool, __is_function_helper<_Tp>::__value> { };
+ : public integral_constant<bool,
+ (__conv_helper<typename add_reference<_Tp>::type,
+ typename add_pointer<_Tp>::type>::__value)>
+ { };
+ _DEFINE_SPEC(0, is_function, void, false)
/// @brief composite type traits [4.5.2].
template<typename _Tp>
@@ -479,6 +477,31 @@ namespace tr1
remove_all_extents<_Tp>::type>::value)>
{ };
+ // Exploit the resolution DR core/337.
+ template<typename _Tp, bool = (is_void<_Tp>::value
+ || is_function<_Tp>::value
+ || is_reference<_Tp>::value)>
+ struct __is_abstract_helper
+ : public __sfinae_types
+ {
+ private:
+ template<typename>
+ static __one __test(...);
+ template<typename _Up>
+ static __two __test(_Up(*)[1]);
+
+ public:
+ static const bool __value = sizeof(__test<_Tp>(0)) == 1;
+ };
+
+ template<typename _Tp>
+ struct __is_abstract_helper<_Tp, true>
+ { static const bool __value = false; };
+
+ template<typename _Tp>
+ struct is_abstract
+ : public integral_constant<bool, __is_abstract_helper<_Tp>::__value> { };
+
template<typename _Tp>
struct has_trivial_constructor
: public integral_constant<bool, is_pod<_Tp>::value> { };
diff --git a/libstdc++-v3/testsuite/testsuite_tr1.h b/libstdc++-v3/testsuite/testsuite_tr1.h
index aa7855c..74a1876 100644
--- a/libstdc++-v3/testsuite/testsuite_tr1.h
+++ b/libstdc++-v3/testsuite/testsuite_tr1.h
@@ -1,7 +1,7 @@
// -*- C++ -*-
// Testing utilities for the tr1 testsuite.
//
-// Copyright (C) 2004 Free Software Foundation, Inc.
+// Copyright (C) 2004, 2005 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
@@ -117,6 +117,9 @@ namespace __gnu_test
struct ConvType
{ operator int() const; };
+
+ class AbstractClass
+ { virtual void rotate(int) = 0; };
}; // namespace __gnu_test
diff --git a/libstdc++-v3/testsuite/tr1/4_metaprogramming/primary_type_categories/is_function/is_function.cc b/libstdc++-v3/testsuite/tr1/4_metaprogramming/primary_type_categories/is_function/is_function.cc
index 0f79758..4bbda75 100644
--- a/libstdc++-v3/testsuite/tr1/4_metaprogramming/primary_type_categories/is_function/is_function.cc
+++ b/libstdc++-v3/testsuite/tr1/4_metaprogramming/primary_type_categories/is_function/is_function.cc
@@ -1,6 +1,6 @@
// 2004-12-16 Paolo Carlini <pcarlini@suse.de>
//
-// Copyright (C) 2004 Free Software Foundation, Inc.
+// Copyright (C) 2004, 2005 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
@@ -39,6 +39,8 @@ void test01()
VERIFY( (test_category<is_function, int&>(false)) );
VERIFY( (test_category<is_function, void>(false)) );
VERIFY( (test_category<is_function, const void>(false)) );
+
+ VERIFY( (test_category<is_function, AbstractClass>(false)) );
// Sanity check.
VERIFY( (test_category<is_function, ClassType>(false)) );
diff --git a/libstdc++-v3/testsuite/tr1/4_metaprogramming/type_properties/is_abstract/is_abstract.cc b/libstdc++-v3/testsuite/tr1/4_metaprogramming/type_properties/is_abstract/is_abstract.cc
new file mode 100644
index 0000000..70e3ac8
--- /dev/null
+++ b/libstdc++-v3/testsuite/tr1/4_metaprogramming/type_properties/is_abstract/is_abstract.cc
@@ -0,0 +1,49 @@
+// 2005-01-28 Paolo Carlini <pcarlini@suse.de>
+//
+// Copyright (C) 2005 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+// USA.
+
+// 4.5.3 Type properties
+
+#include <tr1/type_traits>
+#include <testsuite_hooks.h>
+#include <testsuite_tr1.h>
+
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+ using std::tr1::is_abstract;
+ using namespace __gnu_test;
+
+ // Positive tests.
+ VERIFY( (test_category<is_abstract, AbstractClass>(true)) );
+
+ // Negative tests.
+ VERIFY( (test_category<is_abstract, void>(false)) );
+ VERIFY( (test_category<is_abstract, int (int)>(false)) );
+ VERIFY( (test_category<is_abstract, int&>(false)) );
+
+ // Sanity check.
+ VERIFY( (test_category<is_abstract, ClassType>(false)) );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/tr1/4_metaprogramming/type_properties/is_abstract/typedefs.cc b/libstdc++-v3/testsuite/tr1/4_metaprogramming/type_properties/is_abstract/typedefs.cc
new file mode 100644
index 0000000..c781c55
--- /dev/null
+++ b/libstdc++-v3/testsuite/tr1/4_metaprogramming/type_properties/is_abstract/typedefs.cc
@@ -0,0 +1,36 @@
+// 2005-01-28 Paolo Carlini <pcarlini@suse.de>
+//
+// Copyright (C) 2005 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+// USA.
+
+//
+// NB: This file is for testing tr1/type_traits with NO OTHER INCLUDES.
+
+#include <tr1/type_traits>
+
+// { dg-do compile }
+
+void test01()
+{
+ // Check for required typedefs
+ typedef std::tr1::is_abstract<int> test_type;
+ typedef test_type::value_type value_type;
+ typedef test_type::type type;
+ typedef test_type::type::value_type type_value_type;
+ typedef test_type::type::type type_type;
+}