This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[v3] tr1/type_traits: is_signed/is_unsigned


Hi,

the below implements the letter of the current (january, 17)
draft, confirmed by Matt on the reflector. Maybe things will
change (before 4.0?), in case, updates will follow...

Tested x86-linux, committed.

Paolo.

/////////////
2005-01-24  Paolo Carlini  <pcarlini@suse.de>

	* include/tr1/type_traits: Implement is_signed and is_unsigned.
	* testsuite/tr1/4_metaprogramming/type_properties/
	is_signed/is_signed.cc: New.
	* testsuite/tr1/4_metaprogramming/type_properties/
	is_signed/typedefs.cc: Likewise.
	* testsuite/tr1/4_metaprogramming/type_properties/
	is_unsigned/is_unsigned.cc: Likewise.
	* testsuite/tr1/4_metaprogramming/type_properties/
	is_unsigned/typedefs.cc: Likewise.
diff -urN libstdc++-v3-orig/include/tr1/type_traits libstdc++-v3/include/tr1/type_traits
--- libstdc++-v3-orig/include/tr1/type_traits	2005-01-23 12:10:37.000000000 +0100
+++ libstdc++-v3/include/tr1/type_traits	2005-01-24 14:22:53.000000000 +0100
@@ -517,6 +517,24 @@
     struct has_virtual_destructor
     : public false_type { };
 
+  template<typename>
+    struct is_signed
+    : public false_type { };
+  _DEFINE_SPEC(0, is_signed, signed char, true)
+  _DEFINE_SPEC(0, is_signed, short, true)
+  _DEFINE_SPEC(0, is_signed, int, true)
+  _DEFINE_SPEC(0, is_signed, long, true)
+  _DEFINE_SPEC(0, is_signed, long long, true)
+
+  template<typename>
+    struct is_unsigned
+    : public false_type { };
+  _DEFINE_SPEC(0, is_unsigned, unsigned char, true)
+  _DEFINE_SPEC(0, is_unsigned, unsigned short, true)
+  _DEFINE_SPEC(0, is_unsigned, unsigned int, true)
+  _DEFINE_SPEC(0, is_unsigned, unsigned long, true)
+  _DEFINE_SPEC(0, is_unsigned, unsigned long long, true)
+
   template<typename _Tp>
     struct alignment_of
     : public integral_constant<std::size_t, __alignof__(_Tp)> { };
diff -urN libstdc++-v3-orig/testsuite/tr1/4_metaprogramming/type_properties/is_signed/is_signed.cc libstdc++-v3/testsuite/tr1/4_metaprogramming/type_properties/is_signed/is_signed.cc
--- libstdc++-v3-orig/testsuite/tr1/4_metaprogramming/type_properties/is_signed/is_signed.cc	1970-01-01 01:00:00.000000000 +0100
+++ libstdc++-v3/testsuite/tr1/4_metaprogramming/type_properties/is_signed/is_signed.cc	2005-01-24 14:29:03.000000000 +0100
@@ -0,0 +1,62 @@
+// 2005-01-24  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_signed;
+  using namespace __gnu_test;
+  
+  VERIFY( (test_category<is_signed, void>(false)) );
+  
+  VERIFY( (test_category<is_signed, char>(false)) );
+  VERIFY( (test_category<is_signed, signed char>(true)) );
+  VERIFY( (test_category<is_signed, unsigned char>(false)) );
+#ifdef _GLIBCXX_USE_WCHAR_T
+  VERIFY( (test_category<is_signed, wchar_t>(false)) );
+#endif
+  VERIFY( (test_category<is_signed, short>(true)) );
+  VERIFY( (test_category<is_signed, unsigned short>(false)) );
+  VERIFY( (test_category<is_signed, int>(true)) );
+  VERIFY( (test_category<is_signed, unsigned int>(false)) );
+  VERIFY( (test_category<is_signed, long>(true)) );
+  VERIFY( (test_category<is_signed, unsigned long>(false)) );
+  VERIFY( (test_category<is_signed, long long>(true)) );
+  VERIFY( (test_category<is_signed, unsigned long long>(false)) );
+
+  VERIFY( (test_category<is_signed, float>(false)) );
+  VERIFY( (test_category<is_signed, double>(false)) );
+  VERIFY( (test_category<is_signed, long double>(false)) );
+
+  // Sanity check.
+  VERIFY( (test_category<is_signed, ClassType>(false)) );
+}
+
+int main()
+{
+  test01();
+  return 0;
+}
diff -urN libstdc++-v3-orig/testsuite/tr1/4_metaprogramming/type_properties/is_signed/typedefs.cc libstdc++-v3/testsuite/tr1/4_metaprogramming/type_properties/is_signed/typedefs.cc
--- libstdc++-v3-orig/testsuite/tr1/4_metaprogramming/type_properties/is_signed/typedefs.cc	1970-01-01 01:00:00.000000000 +0100
+++ libstdc++-v3/testsuite/tr1/4_metaprogramming/type_properties/is_signed/typedefs.cc	2005-01-24 14:26:28.000000000 +0100
@@ -0,0 +1,36 @@
+// 2005-01-24  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_signed<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;
+}
diff -urN libstdc++-v3-orig/testsuite/tr1/4_metaprogramming/type_properties/is_unsigned/is_unsigned.cc libstdc++-v3/testsuite/tr1/4_metaprogramming/type_properties/is_unsigned/is_unsigned.cc
--- libstdc++-v3-orig/testsuite/tr1/4_metaprogramming/type_properties/is_unsigned/is_unsigned.cc	1970-01-01 01:00:00.000000000 +0100
+++ libstdc++-v3/testsuite/tr1/4_metaprogramming/type_properties/is_unsigned/is_unsigned.cc	2005-01-24 14:32:06.000000000 +0100
@@ -0,0 +1,62 @@
+// 2005-01-24  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_unsigned;
+  using namespace __gnu_test;
+  
+  VERIFY( (test_category<is_unsigned, void>(false)) );
+  
+  VERIFY( (test_category<is_unsigned, char>(false)) );
+  VERIFY( (test_category<is_unsigned, signed char>(false)) );
+  VERIFY( (test_category<is_unsigned, unsigned char>(true)) );
+#ifdef _GLIBCXX_USE_WCHAR_T
+  VERIFY( (test_category<is_unsigned, wchar_t>(false)) );
+#endif
+  VERIFY( (test_category<is_unsigned, short>(false)) );
+  VERIFY( (test_category<is_unsigned, unsigned short>(true)) );
+  VERIFY( (test_category<is_unsigned, int>(false)) );
+  VERIFY( (test_category<is_unsigned, unsigned int>(true)) );
+  VERIFY( (test_category<is_unsigned, long>(false)) );
+  VERIFY( (test_category<is_unsigned, unsigned long>(true)) );
+  VERIFY( (test_category<is_unsigned, long long>(false)) );
+  VERIFY( (test_category<is_unsigned, unsigned long long>(true)) );
+
+  VERIFY( (test_category<is_unsigned, float>(false)) );
+  VERIFY( (test_category<is_unsigned, double>(false)) );
+  VERIFY( (test_category<is_unsigned, long double>(false)) );
+
+  // Sanity check.
+  VERIFY( (test_category<is_unsigned, ClassType>(false)) );
+}
+
+int main()
+{
+  test01();
+  return 0;
+}
diff -urN libstdc++-v3-orig/testsuite/tr1/4_metaprogramming/type_properties/is_unsigned/typedefs.cc libstdc++-v3/testsuite/tr1/4_metaprogramming/type_properties/is_unsigned/typedefs.cc
--- libstdc++-v3-orig/testsuite/tr1/4_metaprogramming/type_properties/is_unsigned/typedefs.cc	1970-01-01 01:00:00.000000000 +0100
+++ libstdc++-v3/testsuite/tr1/4_metaprogramming/type_properties/is_unsigned/typedefs.cc	2005-01-24 14:30:49.000000000 +0100
@@ -0,0 +1,36 @@
+// 2005-01-24  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_unsigned<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;
+}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]