aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaolo Carlini <pcarlini@suse.de>2004-12-25 15:24:36 +0000
committerPaolo Carlini <paolo@gcc.gnu.org>2004-12-25 15:24:36 +0000
commita9e7ba81398e8157a97d2d626509dd53ee7eed26 (patch)
tree4b05911b8080767aa711d21449e7e582f9cf097f
parent7f514158b2a4eae91168bc4e173f99244e65a3e0 (diff)
downloadgcc-a9e7ba81398e8157a97d2d626509dd53ee7eed26.zip
gcc-a9e7ba81398e8157a97d2d626509dd53ee7eed26.tar.gz
gcc-a9e7ba81398e8157a97d2d626509dd53ee7eed26.tar.bz2
type_traits: Implement is_enum (usual caveats about the nasty consequences of c++/19076...).
2004-12-25 Paolo Carlini <pcarlini@suse.de> * include/tr1/type_traits: Implement is_enum (usual caveats about the nasty consequences of c++/19076...). * testsuite/testsuite_tr1.h: Add ConvType. * testsuite/tr1/4_metaprogramming/composite_type_traits/ is_scalar/is_scalar.cc: New. * testsuite/tr1/4_metaprogramming/composite_type_traits/ is_scalar/typedefs.cc: Likewise. * testsuite/tr1/4_metaprogramming/primary_type_categories/ is_enum/is_enum.cc: Likewise. * testsuite/tr1/4_metaprogramming/primary_type_categories/ is_enum/typedefs.cc: Likewise. From-SVN: r92604
-rw-r--r--libstdc++-v3/ChangeLog14
-rw-r--r--libstdc++-v3/include/tr1/type_traits56
-rw-r--r--libstdc++-v3/testsuite/testsuite_tr1.h6
-rw-r--r--libstdc++-v3/testsuite/tr1/4_metaprogramming/composite_type_traits/is_scalar/is_scalar.cc50
-rw-r--r--libstdc++-v3/testsuite/tr1/4_metaprogramming/composite_type_traits/is_scalar/typedefs.cc36
-rw-r--r--libstdc++-v3/testsuite/tr1/4_metaprogramming/primary_type_categories/is_enum/is_enum.cc60
-rw-r--r--libstdc++-v3/testsuite/tr1/4_metaprogramming/primary_type_categories/is_enum/typedefs.cc36
7 files changed, 252 insertions, 6 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index 6e81728..b644e00 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,3 +1,17 @@
+2004-12-25 Paolo Carlini <pcarlini@suse.de>
+
+ * include/tr1/type_traits: Implement is_enum (usual caveats about
+ the nasty consequences of c++/19076...).
+ * testsuite/testsuite_tr1.h: Add ConvType.
+ * testsuite/tr1/4_metaprogramming/composite_type_traits/
+ is_scalar/is_scalar.cc: New.
+ * testsuite/tr1/4_metaprogramming/composite_type_traits/
+ is_scalar/typedefs.cc: Likewise.
+ * testsuite/tr1/4_metaprogramming/primary_type_categories/
+ is_enum/is_enum.cc: Likewise.
+ * testsuite/tr1/4_metaprogramming/primary_type_categories/
+ is_enum/typedefs.cc: Likewise.
+
2004-12-24 Paolo Carlini <pcarlini@suse.de>
* include/tr1/type_traits: Add missing undef.
diff --git a/libstdc++-v3/include/tr1/type_traits b/libstdc++-v3/include/tr1/type_traits
index 42f9bac..9816ada 100644
--- a/libstdc++-v3/include/tr1/type_traits
+++ b/libstdc++-v3/include/tr1/type_traits
@@ -33,7 +33,7 @@ namespace std
{
namespace tr1
{
- // For use in is_function and elsewhere.
+ // For use in is_enum, is_function, and elsewhere.
struct __sfinae_types
{
typedef char __one;
@@ -149,14 +149,57 @@ namespace tr1
: public false_type { };
_DEFINE_SPEC(2, is_member_function_pointer, _Tp _Cp::*)
+ 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_function<_Tp>::value)>
+ struct __is_enum_helper
+ : public __sfinae_types
+ {
+ private:
+ static __one __test(bool);
+ static __one __test(char);
+ static __one __test(signed char);
+ static __one __test(unsigned char);
+#ifdef _GLIBCXX_USE_WCHAR_T
+ static __one __test(wchar_t);
+#endif
+ static __one __test(short);
+ static __one __test(unsigned short);
+ static __one __test(int);
+ static __one __test(unsigned int);
+ static __one __test(long);
+ static __one __test(unsigned long);
+ static __one __test(long long);
+ static __one __test(unsigned long long);
+ static __two __test(...);
+
+ template<typename _Up>
+ struct __convert
+ { operator _Up() const; };
+
+ public:
+ static const bool __value = sizeof(__test(__convert<_Tp>())) == 1;
+ };
+
template<typename _Tp>
+ struct __is_enum_helper<_Tp, true>
+ { static const bool __value = false; };
+
+ template<typename _Tp>
+ struct is_enum
+ : integral_constant<bool, __is_enum_helper<_Tp>::__value> { };
+
+ template<typename _Tp, bool = (is_reference<_Tp>::value
+ || is_void<_Tp>::value)>
struct __is_function_helper
: public __sfinae_types
{
private:
template<typename>
static __one __test(...);
-
template<typename _Up>
static __two __test(_Up(*)[1]);
@@ -165,11 +208,12 @@ namespace tr1
};
template<typename _Tp>
+ struct __is_function_helper<_Tp, true>
+ { static const bool __value = false; };
+
+ template<typename _Tp>
struct is_function
- : public integral_constant<bool, (__is_function_helper<_Tp>::__value
- && !is_reference<_Tp>::value
- && !is_void<_Tp>::value)>
- { };
+ : public integral_constant<bool, __is_function_helper<_Tp>::__value> { };
/// @brief composite type traits [4.5.2].
template<typename _Tp>
diff --git a/libstdc++-v3/testsuite/testsuite_tr1.h b/libstdc++-v3/testsuite/testsuite_tr1.h
index c9d8d23..0ad8ac1 100644
--- a/libstdc++-v3/testsuite/testsuite_tr1.h
+++ b/libstdc++-v3/testsuite/testsuite_tr1.h
@@ -78,6 +78,12 @@ namespace __gnu_test
typedef const ClassType cClassType;
typedef volatile ClassType vClassType;
typedef const volatile ClassType cvClassType;
+
+ enum EnumType { };
+
+ struct ConvType
+ { operator int() const; };
+
}; // namespace __gnu_test
#endif // _GLIBCXX_TESTSUITE_TR1_H
diff --git a/libstdc++-v3/testsuite/tr1/4_metaprogramming/composite_type_traits/is_scalar/is_scalar.cc b/libstdc++-v3/testsuite/tr1/4_metaprogramming/composite_type_traits/is_scalar/is_scalar.cc
new file mode 100644
index 0000000..37d6592
--- /dev/null
+++ b/libstdc++-v3/testsuite/tr1/4_metaprogramming/composite_type_traits/is_scalar/is_scalar.cc
@@ -0,0 +1,50 @@
+// 2004-12-25 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.2 Composite type traits
+
+#include <tr1/type_traits>
+#include <testsuite_hooks.h>
+#include <testsuite_tr1.h>
+
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+ using std::tr1::is_scalar;
+ using namespace __gnu_test;
+
+ VERIFY( (test_category<is_scalar, int>(true)) );
+ VERIFY( (test_category<is_scalar, float>(true)) );
+ VERIFY( (test_category<is_scalar, EnumType>(true)) );
+ VERIFY( (test_category<is_scalar, int*>(true)) );
+ VERIFY( (test_category<is_scalar, int(*)(int)>(true)) );
+ VERIFY( (test_category<is_scalar, int (ClassType::*)>(true)) );
+ // Temporarily disabled because of c++/19076 :-(
+ // VERIFY( (test_category<is_scalar, int (ClassType::*) (int)>(true)) );
+
+ // Sanity check.
+ VERIFY( (test_category<is_scalar, ClassType>(false)) );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/tr1/4_metaprogramming/composite_type_traits/is_scalar/typedefs.cc b/libstdc++-v3/testsuite/tr1/4_metaprogramming/composite_type_traits/is_scalar/typedefs.cc
new file mode 100644
index 0000000..5a1740f
--- /dev/null
+++ b/libstdc++-v3/testsuite/tr1/4_metaprogramming/composite_type_traits/is_scalar/typedefs.cc
@@ -0,0 +1,36 @@
+// 2004-12-25 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_scalar<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/primary_type_categories/is_enum/is_enum.cc b/libstdc++-v3/testsuite/tr1/4_metaprogramming/primary_type_categories/is_enum/is_enum.cc
new file mode 100644
index 0000000..3de48c4
--- /dev/null
+++ b/libstdc++-v3/testsuite/tr1/4_metaprogramming/primary_type_categories/is_enum/is_enum.cc
@@ -0,0 +1,60 @@
+// 2004-12-25 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>
+
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+ using std::tr1::is_enum;
+ using namespace __gnu_test;
+
+ // Positive tests.
+ VERIFY( (test_category<is_enum, EnumType>(true)) );
+
+ // Negative tests.
+ VERIFY( (test_category<is_enum, void>(false)) );
+ VERIFY( (test_category<is_enum, int>(false)) );
+ VERIFY( (test_category<is_enum, float>(false)) );
+ VERIFY( (test_category<is_enum, int[2]>(false)) );
+ VERIFY( (test_category<is_enum, int*>(false)) );
+ VERIFY( (test_category<is_enum, int(*)(int)>(false)) );
+ VERIFY( (test_category<is_enum, float&>(false)) );
+ VERIFY( (test_category<is_enum, float(&)(float)>(false)) );
+ VERIFY( (test_category<is_enum, int (ClassType::*)>(false)) );
+ // Temporarily disabled because of c++/19076 :-(
+ // VERIFY( (test_category<is_enum, int (ClassType::*) (int)>(false)) );
+ VERIFY( (test_category<is_enum, int (int)>(false)) );
+
+ VERIFY( (test_category<is_enum, ConvType>(false)) );
+
+ // Sanity check.
+ VERIFY( (test_category<is_enum, ClassType>(false)) );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/tr1/4_metaprogramming/primary_type_categories/is_enum/typedefs.cc b/libstdc++-v3/testsuite/tr1/4_metaprogramming/primary_type_categories/is_enum/typedefs.cc
new file mode 100644
index 0000000..eeb1093
--- /dev/null
+++ b/libstdc++-v3/testsuite/tr1/4_metaprogramming/primary_type_categories/is_enum/typedefs.cc
@@ -0,0 +1,36 @@
+// 2004-12-25 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_enum<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;
+}