From 6b560c323c779400f5821db543f191f435d6c5d9 Mon Sep 17 00:00:00 2001
From: paolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4>
Date: Fri, 28 Jan 2005 17:20:43 +0000
Subject: [PATCH] 2005-01-28  Paolo Carlini  <pcarlini@suse.de>

	* include/tr1/type_traits: Implement is_empty.
	* testsuite/tr1/4_metaprogramming/type_properties/is_empty/
	is_empty.cc: New.
	* testsuite/tr1/4_metaprogramming/type_properties/is_empty/
	typedefs.cc: Likewise.

	* include/tr1/type_traits (__is_abstract_helper): Simplify a bit.


git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@94379 138bc75d-0d04-0410-961f-82ee72b054a4
---
 libstdc++-v3/ChangeLog                        | 10 +++
 libstdc++-v3/include/tr1/type_traits          | 34 ++++++++-
 .../type_properties/is_empty/is_empty.cc      | 73 +++++++++++++++++++
 .../type_properties/is_empty/typedefs.cc      | 36 +++++++++
 4 files changed, 150 insertions(+), 3 deletions(-)
 create mode 100644 libstdc++-v3/testsuite/tr1/4_metaprogramming/type_properties/is_empty/is_empty.cc
 create mode 100644 libstdc++-v3/testsuite/tr1/4_metaprogramming/type_properties/is_empty/typedefs.cc

diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index f9b1de548ba6..eda22a8d5675 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,3 +1,13 @@
+2005-01-28  Paolo Carlini  <pcarlini@suse.de>
+
+	* include/tr1/type_traits: Implement is_empty.
+	* testsuite/tr1/4_metaprogramming/type_properties/is_empty/
+	is_empty.cc: New.
+	* testsuite/tr1/4_metaprogramming/type_properties/is_empty/
+	typedefs.cc: Likewise.
+
+	* include/tr1/type_traits (__is_abstract_helper): Simplify a bit.
+
 2005-01-28  Paolo Carlini  <pcarlini@suse.de>
 
 	* include/tr1/type_traits: Implement is_abstract, by exploiting the
diff --git a/libstdc++-v3/include/tr1/type_traits b/libstdc++-v3/include/tr1/type_traits
index d75e5dffb103..753722941f9d 100644
--- a/libstdc++-v3/include/tr1/type_traits
+++ b/libstdc++-v3/include/tr1/type_traits
@@ -477,10 +477,38 @@ namespace tr1
 				      remove_all_extents<_Tp>::type>::value)>
     { };
 
+  template<typename>
+    struct __is_empty_helper_1
+    { };
+
+  template<typename _Tp>
+    struct __is_empty_helper_2
+    : public _Tp { };
+
+  // Unfortunately, without compiler support we cannot tell union from
+  // class types, and is_empty doesn't work at all with the former. 
+  template<typename _Tp, bool = (is_fundamental<_Tp>::value
+				 || is_array<_Tp>::value
+				 || is_pointer<_Tp>::value
+				 || is_reference<_Tp>::value
+				 || is_member_pointer<_Tp>::value
+				 || is_enum<_Tp>::value
+				 || is_function<_Tp>::value)>
+    struct __is_empty_helper
+    { static const bool __value = (sizeof(__is_empty_helper_1<_Tp>)
+				   == sizeof(__is_empty_helper_2<_Tp>)); };
+
+  template<typename _Tp>
+    struct __is_empty_helper<_Tp, true>
+    { static const bool __value = false; };
+
+  template<typename _Tp>
+    struct is_empty
+    : public integral_constant<bool, __is_empty_helper<_Tp>::__value>
+    { };
+
   // Exploit the resolution DR core/337.
-  template<typename _Tp, bool = (is_void<_Tp>::value
-				 || is_function<_Tp>::value
-				 || is_reference<_Tp>::value)>
+  template<typename _Tp, bool = !is_object<_Tp>::value>
     struct __is_abstract_helper
     : public __sfinae_types
     {
diff --git a/libstdc++-v3/testsuite/tr1/4_metaprogramming/type_properties/is_empty/is_empty.cc b/libstdc++-v3/testsuite/tr1/4_metaprogramming/type_properties/is_empty/is_empty.cc
new file mode 100644
index 000000000000..861105498aad
--- /dev/null
+++ b/libstdc++-v3/testsuite/tr1/4_metaprogramming/type_properties/is_empty/is_empty.cc
@@ -0,0 +1,73 @@
+// 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>
+
+class EmptyClassOne
+{ typedef int type; };
+
+class EmptyClassTwo
+{ static int data; };
+
+class EmptyClassThree
+{ int f(); };
+
+class NonEmptyClassOne
+{ int data; };
+
+class NonEmptyClassTwo
+{ virtual int f(); };
+
+void test01()
+{
+  bool test __attribute__((unused)) = true;
+  using std::tr1::is_empty;
+  using namespace __gnu_test;
+
+  // Positive tests.
+  VERIFY( (test_category<is_empty, ClassType>(true)) );
+  VERIFY( (test_category<is_empty, EmptyClassOne>(true)) );
+  VERIFY( (test_category<is_empty, EmptyClassTwo>(true)) );
+  VERIFY( (test_category<is_empty, EmptyClassThree>(true)) );
+
+  // Negative tests.
+  VERIFY( (test_category<is_empty, void>(false)) );
+  VERIFY( (test_category<is_empty, float>(false)) );
+  VERIFY( (test_category<is_empty, int[4]>(false)) );
+  VERIFY( (test_category<is_empty, int*>(false)) );
+  VERIFY( (test_category<is_empty, int&>(false)) );
+  VERIFY( (test_category<is_empty, int (ClassType::*)>(false)) );
+  VERIFY( (test_category<is_empty, EnumType>(false)) );
+  VERIFY( (test_category<is_empty, int (int)>(false)) );
+
+  VERIFY( (test_category<is_empty, AbstractClass>(false)) );
+  VERIFY( (test_category<is_empty, NonEmptyClassOne>(false)) );
+  VERIFY( (test_category<is_empty, NonEmptyClassTwo>(false)) );  
+}
+
+int main()
+{
+  test01();
+  return 0;
+}
diff --git a/libstdc++-v3/testsuite/tr1/4_metaprogramming/type_properties/is_empty/typedefs.cc b/libstdc++-v3/testsuite/tr1/4_metaprogramming/type_properties/is_empty/typedefs.cc
new file mode 100644
index 000000000000..9ffc041606dc
--- /dev/null
+++ b/libstdc++-v3/testsuite/tr1/4_metaprogramming/type_properties/is_empty/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_empty<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;
+}
-- 
GitLab