aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libstdc++-v3/ChangeLog14
-rw-r--r--libstdc++-v3/include/tr1/type_traits36
-rw-r--r--libstdc++-v3/testsuite/testsuite_tr1.h2
-rw-r--r--libstdc++-v3/testsuite/tr1/4_metaprogramming/primary_type_categories/is_function/is_function.cc1
-rw-r--r--libstdc++-v3/testsuite/tr1/4_metaprogramming/relationships_between_types/is_convertible/is_convertible.cc79
-rw-r--r--libstdc++-v3/testsuite/tr1/4_metaprogramming/relationships_between_types/is_convertible/typedefs.cc36
6 files changed, 167 insertions, 1 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index bd1091c..14e038d 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,3 +1,17 @@
+2005-02-23 Paolo Carlini <pcarlini@suse.de>
+
+ * include/tr1/type_traits: Implement is_convertible.
+ * testsuite/tr1/4_metaprogramming/relationships_between_types/
+ is_convertible/is_convertible.cc: New.
+ * testsuite/tr1/4_metaprogramming/relationships_between_types/
+ is_convertible/typedefs.cc: Likewise.
+ * testsuite/testsuite_tr1.h: Add class DerivedType.
+
+ * include/tr1/type_traits (is_function): Don't mistake references
+ to function types for function types.
+ * testsuite/tr1/4_metaprogramming/primary_type_categories/
+ is_function/is_function.cc: Add testcase.
+
2005-02-22 Benjamin Kosnik <bkoz@redhat.com>
* scripts/check_performance: Tweaks.
diff --git a/libstdc++-v3/include/tr1/type_traits b/libstdc++-v3/include/tr1/type_traits
index c4c1ff4..0fb5916 100644
--- a/libstdc++-v3/include/tr1/type_traits
+++ b/libstdc++-v3/include/tr1/type_traits
@@ -208,7 +208,8 @@ namespace tr1
struct is_enum
: public integral_constant<bool, __is_enum_helper<_Tp>::__value> { };
- template<typename _Tp, bool = is_void<_Tp>::value>
+ template<typename _Tp, bool = (is_void<_Tp>::value
+ || is_reference<_Tp>::value)>
struct __is_function_helper
{
static const bool __value = (__conv_helper<typename
@@ -440,6 +441,39 @@ namespace tr1
struct is_same<_Tp, _Tp>
: public true_type { };
+ template<typename _Tp>
+ struct __is_int_or_cref
+ {
+ typedef typename remove_reference<_Tp>::type __rr_Tp;
+ static const bool __value = (is_integral<_Tp>::value
+ || (is_integral<__rr_Tp>::value
+ && is_const<__rr_Tp>::value
+ && !is_volatile<__rr_Tp>::value));
+ };
+
+ template<typename _From, typename _To,
+ bool = (is_function<_To>::value || is_array<_To>::value
+ // This special case is here only to avoid warnings.
+ || (is_floating_point<typename
+ remove_reference<_From>::type>::value
+ && __is_int_or_cref<_To>::__value))>
+ struct __is_convertible_helper
+ {
+ // "An imaginary lvalue of type From...".
+ static const bool __value = (__conv_helper<typename
+ add_reference<_From>::type, _To>::__value);
+ };
+
+ template<typename _From, typename _To>
+ struct __is_convertible_helper<_From, _To, true>
+ { static const bool __value = __is_int_or_cref<_To>::__value; };
+
+ template<typename _From, typename _To>
+ struct is_convertible
+ : public integral_constant<bool,
+ __is_convertible_helper<_From, _To>::__value>
+ { };
+
/// @brief const-volatile modifications [4.7.1].
template<typename _Tp>
struct remove_const
diff --git a/libstdc++-v3/testsuite/testsuite_tr1.h b/libstdc++-v3/testsuite/testsuite_tr1.h
index 74a1876..a0302c1 100644
--- a/libstdc++-v3/testsuite/testsuite_tr1.h
+++ b/libstdc++-v3/testsuite/testsuite_tr1.h
@@ -113,6 +113,8 @@ namespace __gnu_test
typedef volatile ClassType vClassType;
typedef const volatile ClassType cvClassType;
+ class DerivedType : public ClassType { };
+
enum EnumType { };
struct ConvType
diff --git a/libstdc++-v3/testsuite/tr1/4_metaprogramming/primary_type_categories/is_function/is_function.cc b/libstdc++-v3/testsuite/tr1/4_metaprogramming/primary_type_categories/is_function/is_function.cc
index 4bbda75..1c8d64d 100644
--- a/libstdc++-v3/testsuite/tr1/4_metaprogramming/primary_type_categories/is_function/is_function.cc
+++ b/libstdc++-v3/testsuite/tr1/4_metaprogramming/primary_type_categories/is_function/is_function.cc
@@ -41,6 +41,7 @@ void test01()
VERIFY( (test_category<is_function, const void>(false)) );
VERIFY( (test_category<is_function, AbstractClass>(false)) );
+ VERIFY( (test_category<is_function, int(&)(int)>(false)) );
// Sanity check.
VERIFY( (test_category<is_function, ClassType>(false)) );
diff --git a/libstdc++-v3/testsuite/tr1/4_metaprogramming/relationships_between_types/is_convertible/is_convertible.cc b/libstdc++-v3/testsuite/tr1/4_metaprogramming/relationships_between_types/is_convertible/is_convertible.cc
new file mode 100644
index 0000000..858bfda
--- /dev/null
+++ b/libstdc++-v3/testsuite/tr1/4_metaprogramming/relationships_between_types/is_convertible/is_convertible.cc
@@ -0,0 +1,79 @@
+// 2005-02-23 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.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_convertible;
+ using namespace __gnu_test;
+
+ // Positive tests.
+ VERIFY( (test_relationship<is_convertible, int, int>(true)) );
+ VERIFY( (test_relationship<is_convertible, int, const int>(true)) );
+ VERIFY( (test_relationship<is_convertible, volatile int, const int>(true)) );
+ VERIFY( (test_relationship<is_convertible, int, float>(true)) );
+ VERIFY( (test_relationship<is_convertible, double, float>(true)) );
+ VERIFY( (test_relationship<is_convertible, float, int>(true)) );
+ VERIFY( (test_relationship<is_convertible, int*, const int*>(true)) );
+ VERIFY( (test_relationship<is_convertible, int*, void*>(true)) );
+ VERIFY( (test_relationship<is_convertible, int[4], int*>(true)) );
+ VERIFY( (test_relationship<is_convertible, float&, int>(true)) );
+ VERIFY( (test_relationship<is_convertible, int, const int&>(true)) );
+ VERIFY( (test_relationship<is_convertible, const int&, int>(true)) );
+ VERIFY( (test_relationship<is_convertible, float, const int&>(true)) );
+ VERIFY( (test_relationship<is_convertible, float, volatile float&>(true)) );
+ VERIFY( (test_relationship<is_convertible, int(int), int(*)(int)>(true)) );
+ VERIFY( (test_relationship<is_convertible, int(int), int(&)(int)>(true)) );
+ VERIFY( (test_relationship<is_convertible, int(&)(int), int(*)(int)>(true)) );
+ VERIFY( (test_relationship<is_convertible, EnumType, int>(true)) );
+ VERIFY( (test_relationship<is_convertible, ClassType, ClassType>(true)) );
+ VERIFY( (test_relationship<is_convertible, DerivedType, ClassType>(true)) );
+ VERIFY( (test_relationship<is_convertible, DerivedType*, ClassType*>(true)) );
+ VERIFY( (test_relationship<is_convertible, DerivedType&, ClassType&>(true)) );
+
+ // Negative tests.
+ VERIFY( (test_relationship<is_convertible, const int*, int*>(false)) );
+ VERIFY( (test_relationship<is_convertible, int*, float*>(false)) );
+ VERIFY( (test_relationship<is_convertible, const int[4], int*>(false)) );
+ VERIFY( (test_relationship<is_convertible, int[4], int[4]>(false)) );
+ VERIFY( (test_relationship<is_convertible, const int&, int&>(false)) );
+ VERIFY( (test_relationship<is_convertible, float&, int&>(false)) );
+ VERIFY( (test_relationship<is_convertible, float, volatile int&>(false)) );
+ VERIFY( (test_relationship<is_convertible, int(int), int(int)>(false)) );
+ VERIFY( (test_relationship<is_convertible, int(int), int(*)(void)>(false)) );
+ VERIFY( (test_relationship<is_convertible, int(*)(int), int(&)(int)>(false)) );
+ VERIFY( (test_relationship<is_convertible, int, EnumType>(false)) );
+ VERIFY( (test_relationship<is_convertible, int, ClassType>(false)) );
+ VERIFY( (test_relationship<is_convertible, ClassType, DerivedType>(false)) );
+ VERIFY( (test_relationship<is_convertible, ClassType*, DerivedType*>(false)) );
+ VERIFY( (test_relationship<is_convertible, ClassType&, DerivedType&>(false)) );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/tr1/4_metaprogramming/relationships_between_types/is_convertible/typedefs.cc b/libstdc++-v3/testsuite/tr1/4_metaprogramming/relationships_between_types/is_convertible/typedefs.cc
new file mode 100644
index 0000000..333c405a
--- /dev/null
+++ b/libstdc++-v3/testsuite/tr1/4_metaprogramming/relationships_between_types/is_convertible/typedefs.cc
@@ -0,0 +1,36 @@
+// 2005-02-23 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_convertible<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;
+}