aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaolo Carlini <pcarlini@suse.de>2004-12-06 15:47:05 +0000
committerPaolo Carlini <paolo@gcc.gnu.org>2004-12-06 15:47:05 +0000
commite21cb773e5cce006984def7d2a35f1bd71ebb65b (patch)
tree886fe1ec57c9225183ed93aa676faa83f8057f23
parenta58d74533c0b06903094936b4d3ba3712fe10ca9 (diff)
downloadgcc-e21cb773e5cce006984def7d2a35f1bd71ebb65b.zip
gcc-e21cb773e5cce006984def7d2a35f1bd71ebb65b.tar.gz
gcc-e21cb773e5cce006984def7d2a35f1bd71ebb65b.tar.bz2
type_traits: Implement is_reference.
2004-12-06 Paolo Carlini <pcarlini@suse.de> * include/tr1/type_traits: Implement is_reference. * testsuite/tr1/4_metaprogramming/primary_type_categories/ is_reference/is_reference.cc: New. * testsuite/tr1/4_metaprogramming/primary_type_categories/ is_reference/typedefs.cc: Likewise. From-SVN: r91779
-rw-r--r--libstdc++-v3/ChangeLog8
-rw-r--r--libstdc++-v3/include/tr1/type_traits11
-rw-r--r--libstdc++-v3/testsuite/tr1/4_metaprogramming/primary_type_categories/is_reference/is_reference.cc51
-rw-r--r--libstdc++-v3/testsuite/tr1/4_metaprogramming/primary_type_categories/is_reference/typedefs.cc36
4 files changed, 103 insertions, 3 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index 744c02c..f7867cb 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,3 +1,11 @@
+2004-12-06 Paolo Carlini <pcarlini@suse.de>
+
+ * include/tr1/type_traits: Implement is_reference.
+ * testsuite/tr1/4_metaprogramming/primary_type_categories/
+ is_reference/is_reference.cc: New.
+ * testsuite/tr1/4_metaprogramming/primary_type_categories/
+ is_reference/typedefs.cc: Likewise.
+
2004-12-05 Paolo Carlini <pcarlini@suse.de>
PR libstdc++/18837
diff --git a/libstdc++-v3/include/tr1/type_traits b/libstdc++-v3/include/tr1/type_traits
index 913a2b7..44d8a4e 100644
--- a/libstdc++-v3/include/tr1/type_traits
+++ b/libstdc++-v3/include/tr1/type_traits
@@ -22,8 +22,8 @@
* This is a TR1 C++ Library header.
*/
-#ifndef _TR1_TYPE_TRAITS
-#define _TR1_TYPE_TRAITS 1
+#ifndef _TYPE_TRAITS
+#define _TYPE_TRAITS 1
#include <bits/c++config.h>
#include <cstddef>
@@ -102,8 +102,13 @@ namespace tr1
template<typename _Tp>
struct is_pointer;
+ template<typename>
+ struct is_reference
+ : public false_type { };
+
template<typename _Tp>
- struct is_reference;
+ struct is_reference<_Tp&>
+ : public true_type { };
template<typename _Tp>
struct is_member_object_pointer;
diff --git a/libstdc++-v3/testsuite/tr1/4_metaprogramming/primary_type_categories/is_reference/is_reference.cc b/libstdc++-v3/testsuite/tr1/4_metaprogramming/primary_type_categories/is_reference/is_reference.cc
new file mode 100644
index 0000000..2442edb3
--- /dev/null
+++ b/libstdc++-v3/testsuite/tr1/4_metaprogramming/primary_type_categories/is_reference/is_reference.cc
@@ -0,0 +1,51 @@
+// 2004-12-06 Paolo Carlini <pcarlini@suse.de>
+//
+// Copyright (C) 2004 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.1 Primary type categories
+
+#include <tr1/type_traits>
+#include <testsuite_hooks.h>
+#include <testsuite_tr1.h>
+
+class ClassType { };
+
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+ using std::tr1::is_reference;
+ using __gnu_test::test_category;
+
+ typedef int& int_ref;
+ typedef ClassType& ClassType_ref;
+ typedef int (&fun_ref) (int);
+
+ VERIFY( (test_category<is_reference, int_ref, true>()) );
+ VERIFY( (test_category<is_reference, ClassType_ref, true>()) );
+ VERIFY( (test_category<is_reference, fun_ref, true>()) );
+
+ // Sanity check.
+ VERIFY( (test_category<is_reference, ClassType, false>()) );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/tr1/4_metaprogramming/primary_type_categories/is_reference/typedefs.cc b/libstdc++-v3/testsuite/tr1/4_metaprogramming/primary_type_categories/is_reference/typedefs.cc
new file mode 100644
index 0000000..ecc197b
--- /dev/null
+++ b/libstdc++-v3/testsuite/tr1/4_metaprogramming/primary_type_categories/is_reference/typedefs.cc
@@ -0,0 +1,36 @@
+// 2004-12-06 Paolo Carlini <pcarlini@suse.de>
+//
+// Copyright (C) 2004 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_reference<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;
+}