]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
2005-01-28 Paolo Carlini <pcarlini@suse.de>
authorpaolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 28 Jan 2005 17:20:43 +0000 (17:20 +0000)
committerpaolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 28 Jan 2005 17:20:43 +0000 (17:20 +0000)
* 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
libstdc++-v3/include/tr1/type_traits
libstdc++-v3/testsuite/tr1/4_metaprogramming/type_properties/is_empty/is_empty.cc [new file with mode: 0644]
libstdc++-v3/testsuite/tr1/4_metaprogramming/type_properties/is_empty/typedefs.cc [new file with mode: 0644]

index f9b1de548ba6b17d5cbde9a58a34068a48ff2887..eda22a8d56755ce4ae870136330db95f31e6056a 100644 (file)
@@ -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
index d75e5dffb1037433fa07c91e6d0c8000a1aefa4c..753722941f9d224852569830a615a895658ed765 100644 (file)
@@ -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 (file)
index 0000000..8611054
--- /dev/null
@@ -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 (file)
index 0000000..9ffc041
--- /dev/null
@@ -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;
+}