summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpaolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4>2004-12-08 16:33:51 +0000
committerpaolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4>2004-12-08 16:33:51 +0000
commitf98c17aae465015bc8abac4bfc039be1b29559d3 (patch)
tree24c5a85cb21522a57213c6802a0471feebedc1e4
parentef31114f01e513345d4b1f2f999b3aec065ada89 (diff)
downloadgcc-f98c17aae465015bc8abac4bfc039be1b29559d3.tar.gz
2004-12-08 Paolo Carlini <pcarlini@suse.de>
* include/tr1/type_traits: Implement is_same, add_reference and remove_reference. * testsuite/testsuite_tr1.h (test_relationship): New. * testsuite/tr1/4_metaprogramming/reference_modifications/ add_reference.cc: New. * testsuite/tr1/4_metaprogramming/reference_modifications/ remove_reference.cc: Likewise. * testsuite/tr1/4_metaprogramming/relationships_between_types/ is_same/is_same.cc: Likewise. * testsuite/tr1/4_metaprogramming/relationships_between_types/ is_same/typedefs.cc: Likewise. * testsuite/tr1/4_metaprogramming/type_properties/is_const/ is_const.cc: Minor tweaks. * testsuite/tr1/4_metaprogramming/type_properties/is_volatile/ is_volatile.cc: Likewise. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@91907 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--libstdc++-v3/ChangeLog19
-rw-r--r--libstdc++-v3/include/tr1/type_traits31
-rw-r--r--libstdc++-v3/testsuite/testsuite_tr1.h29
-rw-r--r--libstdc++-v3/testsuite/tr1/4_metaprogramming/reference_modifications/add_reference.cc46
-rw-r--r--libstdc++-v3/testsuite/tr1/4_metaprogramming/reference_modifications/remove_reference.cc46
-rw-r--r--libstdc++-v3/testsuite/tr1/4_metaprogramming/relationships_between_types/is_same/is_same.cc50
-rw-r--r--libstdc++-v3/testsuite/tr1/4_metaprogramming/relationships_between_types/is_same/typedefs.cc36
-rw-r--r--libstdc++-v3/testsuite/tr1/4_metaprogramming/type_properties/is_const/is_const.cc6
-rw-r--r--libstdc++-v3/testsuite/tr1/4_metaprogramming/type_properties/is_volatile/is_volatile.cc6
9 files changed, 250 insertions, 19 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index 10d7832bc89..2c285e58aa6 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,3 +1,22 @@
+2004-12-08 Paolo Carlini <pcarlini@suse.de>
+
+ * include/tr1/type_traits: Implement is_same, add_reference and
+ remove_reference.
+ * testsuite/testsuite_tr1.h (test_relationship): New.
+ * testsuite/tr1/4_metaprogramming/reference_modifications/
+ add_reference.cc: New.
+ * testsuite/tr1/4_metaprogramming/reference_modifications/
+ remove_reference.cc: Likewise.
+ * testsuite/tr1/4_metaprogramming/relationships_between_types/
+ is_same/is_same.cc: Likewise.
+ * testsuite/tr1/4_metaprogramming/relationships_between_types/
+ is_same/typedefs.cc: Likewise.
+
+ * testsuite/tr1/4_metaprogramming/type_properties/is_const/
+ is_const.cc: Minor tweaks.
+ * testsuite/tr1/4_metaprogramming/type_properties/is_volatile/
+ is_volatile.cc: Likewise.
+
2004-12-08 David Edelsohn <edelsohn@gnu.org>
* Makefile.am (AM_MAKEFLAGS): Remove duplicate LIBCFLAGS and
diff --git a/libstdc++-v3/include/tr1/type_traits b/libstdc++-v3/include/tr1/type_traits
index 928e2aa36e5..742536cb76a 100644
--- a/libstdc++-v3/include/tr1/type_traits
+++ b/libstdc++-v3/include/tr1/type_traits
@@ -240,8 +240,13 @@ namespace tr1
struct extent;
/// @brief relationships between types [4.6].
- template<typename _Tp, typename _Up>
- struct is_same;
+ template<typename, typename>
+ struct is_same
+ : public false_type { };
+
+ template<typename _Tp>
+ struct is_same<_Tp, _Tp>
+ : public true_type { };
template<typename _From, typename _To>
struct is_convertible;
@@ -270,10 +275,28 @@ namespace tr1
/// @brief reference modifications [4.7.2].
template<typename _Tp>
- struct remove_reference;
+ struct remove_reference
+ {
+ typedef _Tp type;
+ };
+
+ template<typename _Tp>
+ struct remove_reference<_Tp&>
+ {
+ typedef _Tp type;
+ };
template<typename _Tp>
- struct add_reference;
+ struct add_reference
+ {
+ typedef _Tp& type;
+ };
+
+ template<typename _Tp>
+ struct add_reference<_Tp&>
+ {
+ typedef _Tp& type;
+ };
/// @brief array modififications [4.7.3].
template<typename _Tp>
diff --git a/libstdc++-v3/testsuite/testsuite_tr1.h b/libstdc++-v3/testsuite/testsuite_tr1.h
index 18563f48e4c..b3d4cf94f17 100644
--- a/libstdc++-v3/testsuite/testsuite_tr1.h
+++ b/libstdc++-v3/testsuite/testsuite_tr1.h
@@ -41,13 +41,13 @@ namespace __gnu_test
{
bool ret = true;
ret &= Category<Type>::value == Tv;
- ret &= Category<Type const>::value == Tv;
- ret &= Category<Type volatile>::value == Tv;
- ret &= Category<Type const volatile>::value == Tv;
+ ret &= Category<const Type>::value == Tv;
+ ret &= Category<volatile Type>::value == Tv;
+ ret &= Category<const volatile Type>::value == Tv;
ret &= Category<Type>::type::value == Tv;
- ret &= Category<Type const>::type::value == Tv;
- ret &= Category<Type volatile>::type::value == Tv;
- ret &= Category<Type const volatile>::type::value == Tv;
+ ret &= Category<const Type>::type::value == Tv;
+ ret &= Category<volatile Type>::type::value == Tv;
+ ret &= Category<const volatile Type>::type::value == Tv;
return ret;
}
@@ -62,11 +62,22 @@ namespace __gnu_test
return ret;
}
+ template<template<typename, typename> class Relationship,
+ typename Type1, typename Type2, bool Tv>
+ bool
+ test_relationship()
+ {
+ bool ret = true;
+ ret &= Relationship<Type1, Type2>::value == Tv;
+ ret &= Relationship<Type1, Type2>::type::value == Tv;
+ return ret;
+ }
+
// Test types.
class ClassType { };
- typedef ClassType const cClassType;
- typedef ClassType volatile vClassType;
- typedef ClassType const volatile cvClassType;
+ typedef const ClassType cClassType;
+ typedef volatile ClassType vClassType;
+ typedef const volatile ClassType cvClassType;
}; // namespace __gnu_test
#endif // _GLIBCXX_TESTSUITE_TR1_H
diff --git a/libstdc++-v3/testsuite/tr1/4_metaprogramming/reference_modifications/add_reference.cc b/libstdc++-v3/testsuite/tr1/4_metaprogramming/reference_modifications/add_reference.cc
new file mode 100644
index 00000000000..7674689433a
--- /dev/null
+++ b/libstdc++-v3/testsuite/tr1/4_metaprogramming/reference_modifications/add_reference.cc
@@ -0,0 +1,46 @@
+// 2004-12-08 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.7.2 Reference modifications
+
+#include <tr1/type_traits>
+#include <testsuite_hooks.h>
+#include <testsuite_tr1.h>
+
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+ using std::tr1::add_reference;
+ using std::tr1::is_same;
+ using namespace __gnu_test;
+
+ VERIFY( (is_same<add_reference<int>::type, int&>::value) );
+ VERIFY( (is_same<add_reference<int&>::type, int&>::value) );
+ VERIFY( (is_same<add_reference<const int>::type, const int&>::value) );
+ VERIFY( (is_same<add_reference<int*>::type, int*&>::value) );
+ VERIFY( (is_same<add_reference<ClassType&>::type, ClassType&>::value) );
+ VERIFY( (is_same<add_reference<ClassType>::type, ClassType&>::value) );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/tr1/4_metaprogramming/reference_modifications/remove_reference.cc b/libstdc++-v3/testsuite/tr1/4_metaprogramming/reference_modifications/remove_reference.cc
new file mode 100644
index 00000000000..f21d1a07cfc
--- /dev/null
+++ b/libstdc++-v3/testsuite/tr1/4_metaprogramming/reference_modifications/remove_reference.cc
@@ -0,0 +1,46 @@
+// 2004-12-08 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.7.2 Reference modifications
+
+#include <tr1/type_traits>
+#include <testsuite_hooks.h>
+#include <testsuite_tr1.h>
+
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+ using std::tr1::remove_reference;
+ using std::tr1::is_same;
+ using namespace __gnu_test;
+
+ VERIFY( (is_same<remove_reference<int&>::type, int>::value) );
+ VERIFY( (is_same<remove_reference<int>::type, int>::value) );
+ VERIFY( (is_same<remove_reference<const int&>::type, const int>::value) );
+ VERIFY( (is_same<remove_reference<int*&>::type, int*>::value) );
+ VERIFY( (is_same<remove_reference<ClassType&>::type, ClassType>::value) );
+ VERIFY( (is_same<remove_reference<ClassType>::type, ClassType>::value) );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/tr1/4_metaprogramming/relationships_between_types/is_same/is_same.cc b/libstdc++-v3/testsuite/tr1/4_metaprogramming/relationships_between_types/is_same/is_same.cc
new file mode 100644
index 00000000000..32d65af4a6d
--- /dev/null
+++ b/libstdc++-v3/testsuite/tr1/4_metaprogramming/relationships_between_types/is_same/is_same.cc
@@ -0,0 +1,50 @@
+// 2004-12-08 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.6 Relationships between types
+
+#include <tr1/type_traits>
+#include <testsuite_hooks.h>
+#include <testsuite_tr1.h>
+
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+ using std::tr1::is_same;
+ using namespace __gnu_test;
+
+ // Positive tests.
+ VERIFY( (test_relationship<is_same, int, int, true>()) );
+ VERIFY( (test_relationship<is_same, const int, const int, true>()) );
+ VERIFY( (test_relationship<is_same, int&, int&, true>()) );
+ VERIFY( (test_relationship<is_same, ClassType, ClassType, true>()) );
+
+ // Negative tests.
+ VERIFY( (test_relationship<is_same, void, int, false>()) );
+ VERIFY( (test_relationship<is_same, int, const int, false>()) );
+ VERIFY( (test_relationship<is_same, int, int&, false>()) );
+ VERIFY( (test_relationship<is_same, int, ClassType, false>()) );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/tr1/4_metaprogramming/relationships_between_types/is_same/typedefs.cc b/libstdc++-v3/testsuite/tr1/4_metaprogramming/relationships_between_types/is_same/typedefs.cc
new file mode 100644
index 00000000000..39c47e24286
--- /dev/null
+++ b/libstdc++-v3/testsuite/tr1/4_metaprogramming/relationships_between_types/is_same/typedefs.cc
@@ -0,0 +1,36 @@
+// 2004-12-08 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_same<int, 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 --git a/libstdc++-v3/testsuite/tr1/4_metaprogramming/type_properties/is_const/is_const.cc b/libstdc++-v3/testsuite/tr1/4_metaprogramming/type_properties/is_const/is_const.cc
index 5202161a132..82de4285aae 100644
--- a/libstdc++-v3/testsuite/tr1/4_metaprogramming/type_properties/is_const/is_const.cc
+++ b/libstdc++-v3/testsuite/tr1/4_metaprogramming/type_properties/is_const/is_const.cc
@@ -31,14 +31,14 @@ void test01()
using namespace __gnu_test;
// Positive tests.
- VERIFY( (test_property<is_const, int const, true>()) );
- VERIFY( (test_property<is_const, int const volatile, true>()) );
+ VERIFY( (test_property<is_const, const int, true>()) );
+ VERIFY( (test_property<is_const, const volatile int, true>()) );
VERIFY( (test_property<is_const, cClassType, true>()) );
VERIFY( (test_property<is_const, cvClassType, true>()) );
// Negative tests.
VERIFY( (test_property<is_const, int, false>()) );
- VERIFY( (test_property<is_const, int volatile, false>()) );
+ VERIFY( (test_property<is_const, volatile int, false>()) );
VERIFY( (test_property<is_const, ClassType, false>()) );
VERIFY( (test_property<is_const, vClassType, false>()) );
}
diff --git a/libstdc++-v3/testsuite/tr1/4_metaprogramming/type_properties/is_volatile/is_volatile.cc b/libstdc++-v3/testsuite/tr1/4_metaprogramming/type_properties/is_volatile/is_volatile.cc
index 4dc791f9c0c..c47ec786aeb 100644
--- a/libstdc++-v3/testsuite/tr1/4_metaprogramming/type_properties/is_volatile/is_volatile.cc
+++ b/libstdc++-v3/testsuite/tr1/4_metaprogramming/type_properties/is_volatile/is_volatile.cc
@@ -31,14 +31,14 @@ void test01()
using namespace __gnu_test;
// Positive tests.
- VERIFY( (test_property<is_volatile, int volatile, true>()) );
- VERIFY( (test_property<is_volatile, int const volatile, true>()) );
+ VERIFY( (test_property<is_volatile, volatile int, true>()) );
+ VERIFY( (test_property<is_volatile, const volatile int, true>()) );
VERIFY( (test_property<is_volatile, vClassType, true>()) );
VERIFY( (test_property<is_volatile, cvClassType, true>()) );
// Negative tests.
VERIFY( (test_property<is_volatile, int, false>()) );
- VERIFY( (test_property<is_volatile, int const, false>()) );
+ VERIFY( (test_property<is_volatile, const int, false>()) );
VERIFY( (test_property<is_volatile, ClassType, false>()) );
VERIFY( (test_property<is_volatile, cClassType, false>()) );
}