This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ 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]

Re: c++0x vs. tr1 type_traits, round 1



Therefore I would ask you to go ahead with something straighforward, as we discussed above: set-up a separate implementation of type_traits for C++0x by copying the current TR1 one, adjusting the names of those 4 traits discussed between yesterday and today, adding the new traits.

Yeah, well.... this doesn't work.


:(

Attached is the seemingly straightforward patch. There are a lot of failures... mainly because large parts of TR1 include tr1/type_traits.

ie:

<bkoz@montsouris> /mnt/share/src/gcc/libstdc++-v3/include/tr1 %grep type_traits * | grep include
common.h:#include <tr1/type_traits>
functional:#include <tr1/type_traits>
functional:#include <ext/type_traits.h>
hashtable:#include <tr1/type_traits> // For true_type and false_type
hashtable_policy.h:#include <ext/type_traits.h>
memory:#include <tr1/type_traits> // tr1::add_reference
random:#include <tr1/type_traits>
random:#include <ext/type_traits.h>
type_traits:#include <tr1/type_traitsfwd.h>



<bkoz@montsouris> /mnt/share/src/gcc/libstdc++-v3/include/std %grep type_traits * | grep include
complex:#include <bits/cpp_type_traits.h>
streambuf:#include <bits/cpp_type_traits.h>
streambuf:#include <ext/type_traits.h>
string:#include <bits/cpp_type_traits.h>
type_traits:/** @file include/type_traits
type_traits:#include <bits/type_traitsfwd.h>


If we go this way, to get things to work we'll have to:

1) add an abstraction header so that we know "which" type_traits to include, ie:

#ifdef __GXX_EXPERIMENTAL_CXX0X__
# include <type_traits>
#else
# include <tr1/type_traits>
#endif

2) fixups for namespace issues, probably fully qualifying all uses
3) potential fixups for name change issues

Thus, this seems less and less straightforward.

This is striking me more and more as the wrong path. Maybe _GLIBCXX_SUPPRESS_TR1 is the way to go after all...

Hmmm...

-benjamin
2007-04-26  Benjamin Kosnik  <bkoz@redhat.com>

	* include/bits/c++config (_GLIBCXX_STD_CXX0X): New.
	* include/std/type_traits (enable_if): New.
	(conditional): New.
	(__decay_selector, decay): New.
	(__cv_selector, __match_cv_qualifiers): New.
	(__make_unsigned, __make_unsigned_selector, make_unsigned): New.
	(__make_signed, __make_signed_selector, make_signed): New.
	Copy in tr1/type_traits, put in namespace _GLIBCXX_STD_CXX0X.
	(has_trivial_default): ... to has_trivial_default_constructor.
	(has_nothrow_default): ... to has_nothrow_default_constructor.
	(has_trivial_copy): ... to has_trivial_copy_constructor.
	(has_nothrow_copy): ... to has_nothrow_copy_constructor.
	Convert _helper to _selector, consistent with other traits usage.
	* include/std/type_traitsfwd.h: New.
	* include/tr1/type_traits: Namespace is always tr1.
	* include/tr1/type_traits_fwd: Move to...
	* include/tr1/type_traitsfwd: ... this, consistency with
	ios/string/locale forward headers.
	* include/Makefile.am (bits_headers): Add type_traitsfwd.h.
	(tr1_headers): Change type_traits_fwd.h to type_traitsfwd.h.
	* include/Makefile.in: Regenerate.

Index: include/bits/c++config
===================================================================
--- include/bits/c++config	(revision 124189)
+++ include/bits/c++config	(working copy)
@@ -156,13 +156,14 @@
 #endif
 
 // Namespace associations for C++0x, TR1 in std.
+# define _GLIBCXX_STD_CXX0X __cxx200x
 #if _GLIBCXX_NAMESPACE_ASSOCIATION_CXX0X
 namespace std
 { 
   namespace __cxx200x { }
   using namespace __cxx200x __attribute__ ((strong)); 
 }
-# define _GLIBCXX_TR1 __cxx200x
+# define _GLIBCXX_TR1 _GLIBCXX_STD_CXX0X
 #else
 # define _GLIBCXX_TR1 tr1
 #endif
Index: include/bits/type_traitsfwd.h
===================================================================
--- include/bits/type_traitsfwd.h	(revision 0)
+++ include/bits/type_traitsfwd.h	(revision 0)
@@ -0,0 +1,221 @@
+// type_traitsfwd.h -*- C++ -*-
+
+// Copyright (C) 2004, 2005, 2006, 2007 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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// As a special exception, you may use this file as part of a free software
+// library without restriction.  Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself cause the resulting executable to be covered by
+// the GNU General Public License.  This exception does not however
+// invalidate any other reasons why the executable file might be covered by
+// the GNU General Public License.
+
+/** @file bits/type_traitsfwd.h
+ *  This is an internal header file, included by other library headers.
+ *  You should not attempt to use it directly.
+ */
+
+#ifndef _GLIBCXX_TYPE_TRAITSFWD
+#define _GLIBCXX_TYPE_TRAITSFWD 1
+
+#include <cstddef>
+
+namespace std
+{
+_GLIBCXX_BEGIN_NAMESPACE(_GLIBCXX_STD_CXX0X)
+
+  /// @brief  helper classes [4.3].
+  template<typename _Tp, _Tp __v>
+    struct integral_constant;
+  typedef integral_constant<bool, true>     true_type;
+  typedef integral_constant<bool, false>    false_type;
+
+  /// @brief  primary type categories [4.5.1].
+  template<typename _Tp>
+    struct is_void;
+
+  template<typename _Tp>
+    struct is_integral;
+
+  template<typename _Tp>
+    struct is_floating_point;
+
+  template<typename _Tp>
+    struct is_array;
+  
+  template<typename _Tp>
+    struct is_pointer;
+ 
+  template<typename _Tp>
+    struct is_reference;
+
+  template<typename _Tp>
+    struct is_member_object_pointer;
+  
+  template<typename _Tp>
+    struct is_member_function_pointer;   
+
+  template<typename _Tp>
+    struct is_enum;
+  
+  template<typename _Tp>
+    struct is_union;
+  
+  template<typename _Tp>
+    struct is_class;
+
+  template<typename _Tp>
+    struct is_function;
+
+  /// @brief  composite type traits [4.5.2].
+  template<typename _Tp>
+    struct is_arithmetic;
+
+  template<typename _Tp>
+    struct is_fundamental;
+
+  template<typename _Tp>
+    struct is_object;
+
+  template<typename _Tp>
+    struct is_scalar;
+
+  template<typename _Tp>
+    struct is_compound;
+
+  template<typename _Tp>
+    struct is_member_pointer;
+
+  /// @brief  type properties [4.5.3].
+  template<typename _Tp>
+    struct is_const;
+  
+  template<typename _Tp>
+    struct is_volatile;
+
+  template<typename _Tp>
+    struct is_pod;
+  
+  template<typename _Tp>
+    struct is_empty;
+  
+  template<typename _Tp>
+    struct is_polymorphic;
+  
+  template<typename _Tp>
+    struct is_abstract;
+  
+  template<typename _Tp>
+    struct has_trivial_constructor;
+  
+  template<typename _Tp>
+    struct has_trivial_copy;
+
+  template<typename _Tp>
+    struct has_trivial_assign;
+  
+  template<typename _Tp>
+    struct has_trivial_destructor;
+  
+  template<typename _Tp>
+    struct has_nothrow_constructor;
+  
+  template<typename _Tp>
+    struct has_nothrow_copy;
+
+  template<typename _Tp>
+    struct has_nothrow_assign;
+  
+  template<typename _Tp>
+    struct has_virtual_destructor;
+  
+  template<typename _Tp>
+    struct is_signed;
+  
+  template<typename _Tp>
+    struct is_unsigned;
+   
+  template<typename _Tp>
+    struct alignment_of;
+  
+  template<typename _Tp>
+    struct rank;
+  
+  template<typename _Tp, unsigned _Uint = 0>
+    struct extent;
+  
+  /// @brief  relationships between types [4.6].
+  template<typename _Tp, typename _Up>
+    struct is_same;
+
+  template<typename _From, typename _To>
+    struct is_convertible;
+
+  template<typename _Base, typename _Derived>
+    struct is_base_of;
+
+  /// @brief  const-volatile modifications [4.7.1].
+  template<typename _Tp>
+    struct remove_const;
+  
+  template<typename _Tp>
+    struct remove_volatile;
+  
+  template<typename _Tp>
+    struct remove_cv;
+  
+  template<typename _Tp>
+    struct add_const;
+   
+  template<typename _Tp>
+    struct add_volatile;
+  
+  template<typename _Tp>
+    struct add_cv;
+
+  /// @brief  reference modifications [4.7.2].
+  template<typename _Tp>
+    struct remove_reference;
+  
+  template<typename _Tp>
+    struct add_reference;
+
+  /// @brief  array modifications [4.7.3].
+  template<typename _Tp>
+    struct remove_extent;
+
+  template<typename _Tp>
+    struct remove_all_extents;
+
+  /// @brief  pointer modifications [4.7.4].
+  template<typename _Tp>
+    struct remove_pointer;
+  
+  template<typename _Tp>
+    struct add_pointer;
+
+  /// @brief  other transformations [4.8].
+  template<std::size_t _Len, std::size_t _Align>
+    struct aligned_storage;
+
+_GLIBCXX_END_NAMESPACE
+}
+
+#endif
Index: include/Makefile.in
===================================================================
--- include/Makefile.in	(revision 124189)
+++ include/Makefile.in	(working copy)
@@ -365,6 +365,7 @@
 	${bits_srcdir}/stl_vector.h \
 	${bits_srcdir}/streambuf.tcc \
 	${bits_srcdir}/stringfwd.h \
+	${bits_srcdir}/type_traitsfwd.h \
 	${bits_srcdir}/valarray_array.h \
 	${bits_srcdir}/valarray_array.tcc \
 	${bits_srcdir}/valarray_before.h \
@@ -822,7 +823,7 @@
 	${tr1_srcdir}/tgmath.h \
 	${tr1_srcdir}/tuple \
 	${tr1_srcdir}/type_traits \
-	${tr1_srcdir}/type_traits_fwd.h \
+	${tr1_srcdir}/type_traitsfwd.h \
 	${tr1_srcdir}/unordered_set \
 	${tr1_srcdir}/unordered_map \
 	${tr1_srcdir}/utility \
Index: include/tr1/type_traits_fwd.h
===================================================================
--- include/tr1/type_traits_fwd.h	(revision 124189)
+++ include/tr1/type_traits_fwd.h	(working copy)
@@ -1,222 +0,0 @@
-// TR1 type_traits -*- C++ -*-
-
-// Copyright (C) 2004, 2005, 2006, 2007 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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
-// USA.
-
-// As a special exception, you may use this file as part of a free software
-// library without restriction.  Specifically, if other files instantiate
-// templates or use macros or inline functions from this file, or you compile
-// this file and link it with other files to produce an executable, this
-// file does not by itself cause the resulting executable to be covered by
-// the GNU General Public License.  This exception does not however
-// invalidate any other reasons why the executable file might be covered by
-// the GNU General Public License.
-
-/** @file tr1/type_traits_fwd.h
- *  This is an internal header file, included by other library headers.
- *  You should not attempt to use it directly.
- */
-
-#ifndef _TYPE_TRAITS_FWD_H
-#define _TYPE_TRAITS_FWD_H 1
-
-#include <cstddef>
-
-// namespace std::tr1
-namespace std
-{
-_GLIBCXX_BEGIN_NAMESPACE(_GLIBCXX_TR1)
-
-  /// @brief  helper classes [4.3].
-  template<typename _Tp, _Tp __v>
-    struct integral_constant;
-  typedef integral_constant<bool, true>     true_type;
-  typedef integral_constant<bool, false>    false_type;
-
-  /// @brief  primary type categories [4.5.1].
-  template<typename _Tp>
-    struct is_void;
-
-  template<typename _Tp>
-    struct is_integral;
-
-  template<typename _Tp>
-    struct is_floating_point;
-
-  template<typename _Tp>
-    struct is_array;
-  
-  template<typename _Tp>
-    struct is_pointer;
- 
-  template<typename _Tp>
-    struct is_reference;
-
-  template<typename _Tp>
-    struct is_member_object_pointer;
-  
-  template<typename _Tp>
-    struct is_member_function_pointer;   
-
-  template<typename _Tp>
-    struct is_enum;
-  
-  template<typename _Tp>
-    struct is_union;
-  
-  template<typename _Tp>
-    struct is_class;
-
-  template<typename _Tp>
-    struct is_function;
-
-  /// @brief  composite type traits [4.5.2].
-  template<typename _Tp>
-    struct is_arithmetic;
-
-  template<typename _Tp>
-    struct is_fundamental;
-
-  template<typename _Tp>
-    struct is_object;
-
-  template<typename _Tp>
-    struct is_scalar;
-
-  template<typename _Tp>
-    struct is_compound;
-
-  template<typename _Tp>
-    struct is_member_pointer;
-
-  /// @brief  type properties [4.5.3].
-  template<typename _Tp>
-    struct is_const;
-  
-  template<typename _Tp>
-    struct is_volatile;
-
-  template<typename _Tp>
-    struct is_pod;
-  
-  template<typename _Tp>
-    struct is_empty;
-  
-  template<typename _Tp>
-    struct is_polymorphic;
-  
-  template<typename _Tp>
-    struct is_abstract;
-  
-  template<typename _Tp>
-    struct has_trivial_constructor;
-  
-  template<typename _Tp>
-    struct has_trivial_copy;
-
-  template<typename _Tp>
-    struct has_trivial_assign;
-  
-  template<typename _Tp>
-    struct has_trivial_destructor;
-  
-  template<typename _Tp>
-    struct has_nothrow_constructor;
-  
-  template<typename _Tp>
-    struct has_nothrow_copy;
-
-  template<typename _Tp>
-    struct has_nothrow_assign;
-  
-  template<typename _Tp>
-    struct has_virtual_destructor;
-  
-  template<typename _Tp>
-    struct is_signed;
-  
-  template<typename _Tp>
-    struct is_unsigned;
-   
-  template<typename _Tp>
-    struct alignment_of;
-  
-  template<typename _Tp>
-    struct rank;
-  
-  template<typename _Tp, unsigned _Uint = 0>
-    struct extent;
-  
-  /// @brief  relationships between types [4.6].
-  template<typename _Tp, typename _Up>
-    struct is_same;
-
-  template<typename _From, typename _To>
-    struct is_convertible;
-
-  template<typename _Base, typename _Derived>
-    struct is_base_of;
-
-  /// @brief  const-volatile modifications [4.7.1].
-  template<typename _Tp>
-    struct remove_const;
-  
-  template<typename _Tp>
-    struct remove_volatile;
-  
-  template<typename _Tp>
-    struct remove_cv;
-  
-  template<typename _Tp>
-    struct add_const;
-   
-  template<typename _Tp>
-    struct add_volatile;
-  
-  template<typename _Tp>
-    struct add_cv;
-
-  /// @brief  reference modifications [4.7.2].
-  template<typename _Tp>
-    struct remove_reference;
-  
-  template<typename _Tp>
-    struct add_reference;
-
-  /// @brief  array modifications [4.7.3].
-  template<typename _Tp>
-    struct remove_extent;
-
-  template<typename _Tp>
-    struct remove_all_extents;
-
-  /// @brief  pointer modifications [4.7.4].
-  template<typename _Tp>
-    struct remove_pointer;
-  
-  template<typename _Tp>
-    struct add_pointer;
-
-  /// @brief  other transformations [4.8].
-  template<std::size_t _Len, std::size_t _Align>
-    struct aligned_storage;
-
-_GLIBCXX_END_NAMESPACE
-}
-
-#endif
Index: include/tr1/type_traitsfwd.h
===================================================================
--- include/tr1/type_traitsfwd.h	(revision 124184)
+++ include/tr1/type_traitsfwd.h	(working copy)
@@ -40,7 +40,7 @@
 // namespace std::tr1
 namespace std
 {
-_GLIBCXX_BEGIN_NAMESPACE(_GLIBCXX_TR1)
+_GLIBCXX_BEGIN_NAMESPACE(tr1)
 
   /// @brief  helper classes [4.3].
   template<typename _Tp, _Tp __v>
Index: include/tr1/type_traits
===================================================================
--- include/tr1/type_traits	(revision 124189)
+++ include/tr1/type_traits	(working copy)
@@ -37,12 +37,12 @@
 #pragma GCC system_header
 
 #include <bits/c++config.h>
-#include <tr1/type_traits_fwd.h>
+#include <tr1/type_traitsfwd.h>
 
 // namespace std::tr1
 namespace std
 {
-_GLIBCXX_BEGIN_NAMESPACE(_GLIBCXX_TR1)
+_GLIBCXX_BEGIN_NAMESPACE(tr1)
 
   // For use in __is_convertible_simple.
   struct __sfinae_types
Index: include/Makefile.am
===================================================================
--- include/Makefile.am	(revision 124189)
+++ include/Makefile.am	(working copy)
@@ -131,6 +131,7 @@
 	${bits_srcdir}/stl_vector.h \
 	${bits_srcdir}/streambuf.tcc \
 	${bits_srcdir}/stringfwd.h \
+	${bits_srcdir}/type_traitsfwd.h \
 	${bits_srcdir}/valarray_array.h \
 	${bits_srcdir}/valarray_array.tcc \
 	${bits_srcdir}/valarray_before.h \
@@ -592,7 +593,7 @@
 	${tr1_srcdir}/tgmath.h \
 	${tr1_srcdir}/tuple \
 	${tr1_srcdir}/type_traits \
-	${tr1_srcdir}/type_traits_fwd.h \
+	${tr1_srcdir}/type_traitsfwd.h \
 	${tr1_srcdir}/unordered_set \
 	${tr1_srcdir}/unordered_map \
 	${tr1_srcdir}/utility \
Index: include/std/type_traits
===================================================================
--- include/std/type_traits	(revision 124189)
+++ include/std/type_traits	(working copy)
@@ -36,11 +36,843 @@
 
 #pragma GCC system_header
 
-#ifdef __GXX_EXPERIMENTAL_CXX0X__
-# include <tr1/type_traits>
-#else
+#ifndef __GXX_EXPERIMENTAL_CXX0X__
 # include <c++0x_warning.h>
 #endif
 
+#include <bits/type_traitsfwd.h>
+
+namespace std
+{
+_GLIBCXX_BEGIN_NAMESPACE(_GLIBCXX_STD_CXX0X)
+
+  // For use in __is_convertible_simple.
+  struct __sfinae_types
+  {
+    typedef char __one;
+    typedef struct { char __arr[2]; } __two;
+  };
+
+#define _DEFINE_SPEC_BODY(_Value)                                    \
+    : public integral_constant<bool, _Value> { };
+
+#define _DEFINE_SPEC_0_HELPER(_Spec, _Value)                         \
+  template<>                                                         \
+    struct _Spec                                                     \
+    _DEFINE_SPEC_BODY(_Value)
+
+#define _DEFINE_SPEC_1_HELPER(_Spec, _Value)                         \
+  template<typename _Tp>                                             \
+    struct _Spec                                                     \
+    _DEFINE_SPEC_BODY(_Value)
+      
+#define _DEFINE_SPEC_2_HELPER(_Spec, _Value)                         \
+  template<typename _Tp, typename _Cp>                               \
+    struct _Spec                                                     \
+    _DEFINE_SPEC_BODY(_Value)
+
+#define _DEFINE_SPEC(_Order, _Trait, _Type, _Value)                  \
+  _DEFINE_SPEC_##_Order##_HELPER(_Trait<_Type>, _Value)              \
+  _DEFINE_SPEC_##_Order##_HELPER(_Trait<_Type const>, _Value)        \
+  _DEFINE_SPEC_##_Order##_HELPER(_Trait<_Type volatile>, _Value)     \
+  _DEFINE_SPEC_##_Order##_HELPER(_Trait<_Type const volatile>, _Value)
+
+  /// @brief  helper classes [4.3].
+  template<typename _Tp, _Tp __v>
+    struct integral_constant
+    {
+      static const _Tp                      value = __v;
+      typedef _Tp                           value_type;
+      typedef integral_constant<_Tp, __v>   type;
+    };
+  typedef integral_constant<bool, true>     true_type;
+  typedef integral_constant<bool, false>    false_type;
+
+  template<typename _Tp, _Tp __v>
+    const _Tp integral_constant<_Tp, __v>::value;
+
+  /// @brief  primary type categories [4.5.1].
+  template<typename>
+    struct is_void
+    : public false_type { };
+  _DEFINE_SPEC(0, is_void, void, true)
+
+  template<typename>
+    struct is_integral
+    : public false_type { };
+  _DEFINE_SPEC(0, is_integral, bool, true)
+  _DEFINE_SPEC(0, is_integral, char, true)
+  _DEFINE_SPEC(0, is_integral, signed char, true)
+  _DEFINE_SPEC(0, is_integral, unsigned char, true)
+#ifdef _GLIBCXX_USE_WCHAR_T
+  _DEFINE_SPEC(0, is_integral, wchar_t, true)
+#endif
+  _DEFINE_SPEC(0, is_integral, short, true)
+  _DEFINE_SPEC(0, is_integral, unsigned short, true)
+  _DEFINE_SPEC(0, is_integral, int, true)
+  _DEFINE_SPEC(0, is_integral, unsigned int, true)
+  _DEFINE_SPEC(0, is_integral, long, true)
+  _DEFINE_SPEC(0, is_integral, unsigned long, true)
+  _DEFINE_SPEC(0, is_integral, long long, true)
+  _DEFINE_SPEC(0, is_integral, unsigned long long, true)
+
+  template<typename>
+    struct is_floating_point
+    : public false_type { };
+  _DEFINE_SPEC(0, is_floating_point, float, true)
+  _DEFINE_SPEC(0, is_floating_point, double, true)
+  _DEFINE_SPEC(0, is_floating_point, long double, true)
+
+  template<typename>
+    struct is_array
+    : public false_type { };
+
+  template<typename _Tp, std::size_t _Size>
+    struct is_array<_Tp[_Size]>
+    : public true_type { };
+
+  template<typename _Tp>
+    struct is_array<_Tp[]>
+    : public true_type { };
+
+  template<typename>
+    struct is_pointer
+    : public false_type { };
+  _DEFINE_SPEC(1, is_pointer, _Tp*, true)
+ 
+  template<typename>
+    struct is_reference
+    : public false_type { };
+
+  template<typename _Tp>
+    struct is_reference<_Tp&>
+    : public true_type { };
+
+  template<typename>
+    struct is_member_object_pointer
+    : public false_type { };
+  _DEFINE_SPEC(2, is_member_object_pointer, _Tp _Cp::*,
+	       !is_function<_Tp>::value)
+
+  template<typename>
+    struct is_member_function_pointer
+    : public false_type { };
+  _DEFINE_SPEC(2, is_member_function_pointer, _Tp _Cp::*,
+	       is_function<_Tp>::value)
+
+  template<typename _Tp>
+    struct is_enum
+    : public integral_constant<bool, __is_enum(_Tp)>
+    { };
+
+  template<typename _Tp>
+    struct is_union
+    : public integral_constant<bool, __is_union(_Tp)>
+    { };
+
+  template<typename _Tp>
+    struct is_class
+    : public integral_constant<bool, __is_class(_Tp)>
+    { };
+
+  template<typename>
+    struct __is_function_selector
+    : public false_type { };
+
+  template<typename _Res, typename... _ArgTypes>
+    struct __is_function_selector<_Res(_ArgTypes...)>
+    : public true_type { };
+
+  template<typename _Res, typename... _ArgTypes>
+    struct __is_function_selector<_Res(_ArgTypes......)>
+    : public true_type { };
+
+  template<typename _Tp>
+    struct is_function
+    : public integral_constant<bool, (__is_function_selector<typename
+				      remove_cv<_Tp>::type>::value)>
+    { };
+
+  /// @brief  composite type traits [4.5.2].
+  template<typename _Tp>
+    struct is_arithmetic
+    : public integral_constant<bool, (is_integral<_Tp>::value
+				      || is_floating_point<_Tp>::value)>
+    { };
+
+  template<typename _Tp>
+    struct is_fundamental
+    : public integral_constant<bool, (is_arithmetic<_Tp>::value
+				      || is_void<_Tp>::value)>
+    { };
+
+  template<typename _Tp>
+    struct is_object
+    : public integral_constant<bool, !(is_function<_Tp>::value
+				       || is_reference<_Tp>::value
+				       || is_void<_Tp>::value)>
+    { };
+
+  template<typename _Tp>
+    struct is_scalar
+    : public integral_constant<bool, (is_arithmetic<_Tp>::value
+				      || is_enum<_Tp>::value
+				      || is_pointer<_Tp>::value
+				      || is_member_pointer<_Tp>::value)>
+    { };
+
+  template<typename _Tp>
+    struct is_compound
+    : public integral_constant<bool, !is_fundamental<_Tp>::value> { };
+
+  template<typename _Tp>
+    struct is_member_pointer
+    : public integral_constant<bool,
+			       (is_member_object_pointer<_Tp>::value
+				|| is_member_function_pointer<_Tp>::value)>
+    { };
+
+  /// @brief  type properties [4.5.3].
+  template<typename>
+    struct is_const
+    : public false_type { };
+
+  template<typename _Tp>
+    struct is_const<_Tp const>
+    : public true_type { };
+  
+  template<typename>
+    struct is_volatile
+    : public false_type { };
+
+  template<typename _Tp>
+    struct is_volatile<_Tp volatile>
+    : public true_type { };
+
+  template<typename _Tp>
+    struct is_pod
+    : public integral_constant<bool, (is_void<_Tp>::value
+				      || is_scalar<typename
+				      remove_all_extents<_Tp>::type>::value)>
+    { };
+
+  template<typename _Tp>
+    struct is_empty
+    : public integral_constant<bool, __is_empty(_Tp)>
+    { };
+
+  template<typename _Tp>
+    struct is_polymorphic
+    : public integral_constant<bool, __is_polymorphic(_Tp)>
+    { };
+
+  template<typename _Tp>
+    struct is_abstract
+    : public integral_constant<bool, __is_abstract(_Tp)>
+    { };
+
+  template<typename _Tp>
+    struct has_trivial_default_constructor
+    : public integral_constant<bool, is_pod<_Tp>::value> { };
+
+  template<typename _Tp>
+    struct has_trivial_copy_constructor
+    : public integral_constant<bool, is_pod<_Tp>::value> { };
+
+  template<typename _Tp>
+    struct has_trivial_assign
+    : public integral_constant<bool, is_pod<_Tp>::value> { };
+
+  template<typename _Tp>
+    struct has_trivial_destructor
+    : public integral_constant<bool, is_pod<_Tp>::value> { };
+
+  template<typename _Tp>
+    struct has_nothrow_default_constructor
+    : public integral_constant<bool, is_pod<_Tp>::value> { };
+
+  template<typename _Tp>
+    struct has_nothrow_copy_constructor
+    : public integral_constant<bool, is_pod<_Tp>::value> { };
+
+  template<typename _Tp>
+    struct has_nothrow_assign
+    : public integral_constant<bool, is_pod<_Tp>::value> { };
+
+  template<typename _Tp>
+    struct has_virtual_destructor
+    : public integral_constant<bool, __has_virtual_destructor(_Tp)>
+    { };
+
+  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)> { };
+  
+  template<typename>
+    struct rank
+    : public integral_constant<std::size_t, 0> { };
+   
+  template<typename _Tp, std::size_t _Size>
+    struct rank<_Tp[_Size]>
+    : public integral_constant<std::size_t, 1 + rank<_Tp>::value> { };
+
+  template<typename _Tp>
+    struct rank<_Tp[]>
+    : public integral_constant<std::size_t, 1 + rank<_Tp>::value> { };
+   
+  template<typename, unsigned>
+    struct extent
+    : public integral_constant<std::size_t, 0> { };
+  
+  template<typename _Tp, unsigned _Uint, std::size_t _Size>
+    struct extent<_Tp[_Size], _Uint>
+    : public integral_constant<std::size_t,
+			       _Uint == 0 ? _Size : extent<_Tp,
+							   _Uint - 1>::value>
+    { };
+
+  template<typename _Tp, unsigned _Uint>
+    struct extent<_Tp[], _Uint>
+    : public integral_constant<std::size_t,
+			       _Uint == 0 ? 0 : extent<_Tp,
+						       _Uint - 1>::value>
+    { };
+  
+  /// @brief  relationships between types [4.6].
+  template<typename, typename>
+    struct is_same
+    : public false_type { };
+
+  template<typename _Tp>
+    struct is_same<_Tp, _Tp>
+    : public true_type { };
+
+  template<typename _Base, typename _Derived>
+    struct __is_base_of_selector
+    {
+      typedef typename remove_cv<_Base>::type    _NoCv_Base;
+      typedef typename remove_cv<_Derived>::type _NoCv_Derived;
+      static const bool __value = (is_same<_Base, _Derived>::value
+				   || (__is_base_of(_Base, _Derived)
+				       && !is_same<_NoCv_Base,
+				                   _NoCv_Derived>::value));
+    };
+ 
+  template<typename _Base, typename _Derived>
+    struct is_base_of
+    : public integral_constant<bool,
+			       __is_base_of_selector<_Base, _Derived>::__value>
+    { };
+
+  template<typename _From, typename _To>
+    struct __is_convertible_simple
+    : public __sfinae_types
+    {
+    private:
+      static __one __test(_To);
+      static __two __test(...);
+      static _From __makeFrom();
+    
+    public:
+      static const bool __value = sizeof(__test(__makeFrom())) == 1;
+    };
+
+  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_void<_From>::value || is_void<_To>::value
+		   || 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_selector
+    {
+      // "An imaginary lvalue of type From...".
+      static const bool __value = (__is_convertible_simple<typename
+				   add_reference<_From>::type, _To>::__value);
+    };
+
+  template<typename _From, typename _To>
+    struct __is_convertible_selector<_From, _To, true>
+    { static const bool __value = (is_void<_To>::value
+				   || (__is_int_or_cref<_To>::__value
+				       && !is_void<_From>::value)); };
+
+  template<typename _From, typename _To>
+    struct is_convertible
+    : public integral_constant<bool,
+			       __is_convertible_selector<_From, _To>::__value>
+    { };
+
+  /// @brief  const-volatile modifications [4.7.1].
+  template<typename _Tp>
+    struct remove_const
+    { typedef _Tp     type; };
+
+  template<typename _Tp>
+    struct remove_const<_Tp const>
+    { typedef _Tp     type; };
+  
+  template<typename _Tp>
+    struct remove_volatile
+    { typedef _Tp     type; };
+
+  template<typename _Tp>
+    struct remove_volatile<_Tp volatile>
+    { typedef _Tp     type; };
+  
+  template<typename _Tp>
+    struct remove_cv
+    {
+      typedef typename
+      remove_const<typename remove_volatile<_Tp>::type>::type     type;
+    };
+  
+  template<typename _Tp>
+    struct add_const
+    { typedef _Tp const     type; };
+   
+  template<typename _Tp>
+    struct add_volatile
+    { typedef _Tp volatile     type; };
+  
+  template<typename _Tp>
+    struct add_cv
+    {
+      typedef typename
+      add_const<typename add_volatile<_Tp>::type>::type     type;
+    };
+
+  /// @brief  reference modifications [4.7.2].
+  template<typename _Tp>
+    struct remove_reference
+    { typedef _Tp     type; };
+
+  template<typename _Tp>
+    struct remove_reference<_Tp&>
+    { typedef _Tp     type; };
+
+  // NB: Careful with reference to void.
+  template<typename _Tp, bool = (is_void<_Tp>::value
+				 || is_reference<_Tp>::value)>
+    struct __add_reference_selector
+    { typedef _Tp&    type; };
+
+  template<typename _Tp>
+    struct __add_reference_selector<_Tp, true>
+    { typedef _Tp     type; };
+
+  template<typename _Tp>
+    struct add_reference
+    : public __add_reference_selector<_Tp>
+    { };
+
+  /// @brief  array modifications [4.7.3].
+  template<typename _Tp>
+    struct remove_extent
+    { typedef _Tp     type; };
+
+  template<typename _Tp, std::size_t _Size>
+    struct remove_extent<_Tp[_Size]>
+    { typedef _Tp     type; };
+
+  template<typename _Tp>
+    struct remove_extent<_Tp[]>
+    { typedef _Tp     type; };
+
+  template<typename _Tp>
+    struct remove_all_extents
+    { typedef _Tp     type; };
+
+  template<typename _Tp, std::size_t _Size>
+    struct remove_all_extents<_Tp[_Size]>
+    { typedef typename remove_all_extents<_Tp>::type     type; };
+
+  template<typename _Tp>
+    struct remove_all_extents<_Tp[]>
+    { typedef typename remove_all_extents<_Tp>::type     type; };
+
+  /// @brief  pointer modifications [4.7.4].
+#undef _DEFINE_SPEC_BODY
+#define _DEFINE_SPEC_BODY(_Value)      \
+    { typedef _Tp     type; };
+
+  template<typename _Tp>
+    struct remove_pointer
+    { typedef _Tp     type; };
+  _DEFINE_SPEC(1, remove_pointer, _Tp*, false)
+  
+  template<typename _Tp>
+    struct add_pointer
+    { typedef typename remove_reference<_Tp>::type*     type; };
+
+  /// @brief  other transformations [4.8].
+  
+  // Due to c++/19163 and c++/17743, for the time being we cannot use
+  // the correct, neat implementation :-(
+  // 
+  // template<std::size_t _Len, std::size_t _Align>
+  //   struct aligned_storage
+  //   { typedef char type[_Len] __attribute__((__aligned__(_Align))); }
+  //
+  // Temporary workaround, useful for Align up to 32:
+  template<std::size_t, std::size_t>
+    struct aligned_storage { };
+
+  template<std::size_t _Len>
+    struct aligned_storage<_Len, 1>
+    {
+      union type
+      {
+	unsigned char __data[_Len];
+	char __align __attribute__((__aligned__(1)));
+      };
+    };
+
+  template<std::size_t _Len>
+    struct aligned_storage<_Len, 2>
+    {
+      union type
+      {
+	unsigned char __data[_Len];
+	char __align __attribute__((__aligned__(2)));
+      };
+    };
+
+  template<std::size_t _Len>
+    struct aligned_storage<_Len, 4>
+    {
+      union type
+      {
+	unsigned char __data[_Len];
+	char __align __attribute__((__aligned__(4)));
+      };
+    };
+
+  template<std::size_t _Len>
+    struct aligned_storage<_Len, 8>
+    {
+      union type
+      {
+	unsigned char __data[_Len];
+	char __align __attribute__((__aligned__(8)));
+      };
+    };
+
+  template<std::size_t _Len>
+    struct aligned_storage<_Len, 16>
+    {
+      union type
+      {
+	unsigned char __data[_Len];
+	char __align __attribute__((__aligned__(16)));
+      };
+    };
+  
+  template<std::size_t _Len>
+    struct aligned_storage<_Len, 32>
+    {
+      union type
+      {
+	unsigned char __data[_Len];
+	char __align __attribute__((__aligned__(32)));
+      };
+    };
+
+#undef _DEFINE_SPEC_0_HELPER
+#undef _DEFINE_SPEC_1_HELPER
+#undef _DEFINE_SPEC_2_HELPER
+#undef _DEFINE_SPEC
+#undef _DEFINE_SPEC_BODY
+
+  // Define a nested type if some predicate holds.
+  template<bool, typename _Tp = void>
+    struct enable_if 
+    { };
+
+  template<typename _Tp>
+    struct enable_if<true, _Tp>
+    { typedef _Tp type; };
+
+
+  // Like a conditional expression, but for types. If true, first, if
+  // false, second.
+  template<bool _Cond, typename _Iftrue, typename _Iffalse>
+    struct conditional
+    { typedef _Iftrue type; };
+
+  template<typename _Iftrue, typename _Iffalse>
+    struct conditional<false, _Iftrue, _Iffalse>
+    { typedef _Iffalse type; };
+
+
+  // Decay trait for arrays and functions, used for perfect forwarding
+  // in make_pair, make_tuple, etc.
+  template<typename _Up, 
+	   bool = is_array<_Up>::value || is_function<_Up>::value> 
+    struct __decay_selector;
+
+  template<typename _Up> 
+    struct __decay_selector<_Up, false>
+    { typedef _Up __type; };
+
+  template<typename _Up> 
+    struct __decay_selector<_Up, true>
+    { 
+    private:
+      static const bool __b = is_array<_Up>::value;
+      typedef typename remove_extent<_Up>::type* __array_type;      
+      typedef typename add_pointer<_Up>::type __function_type;
+      typedef conditional<__b, __array_type, __function_type> __cond;
+
+    public:
+      typedef typename __cond::__type __type;
+    };
+
+  template<typename _Tp> 
+  struct decay : public __decay_selector<typename remove_reference<_Tp>::type>
+    { 
+    private:
+      typedef typename remove_reference<_Tp>::type __remove_type;
+
+    public:
+      typedef typename __decay_selector<__remove_type>::__type type;
+    };
+
+
+  // Utility for constructing identically cv-qualified types.
+  template<typename _Unqualified, bool _IsConst, bool _IsVol>
+    struct __cv_selector;
+
+  template<typename _Unqualified>
+    struct __cv_selector<_Unqualified, false, false>
+    { typedef _Unqualified __type; };
+
+  template<typename _Unqualified>
+    struct __cv_selector<_Unqualified, false, true>
+    { typedef volatile _Unqualified __type; };
+
+  template<typename _Unqualified>
+    struct __cv_selector<_Unqualified, true, false>
+    { typedef const _Unqualified __type; };
+
+  template<typename _Unqualified>
+    struct __cv_selector<_Unqualified, true, true>
+    { typedef const volatile _Unqualified __type; };
+
+  template<typename _Qualified, typename _Unqualified,
+	   bool _IsConst = is_const<_Qualified>::value,
+	   bool _IsVol = is_volatile<_Qualified>::value>
+    struct __match_cv_qualifiers
+    {
+    private:
+      typedef __cv_selector<_Unqualified, _IsConst, _IsVol> __match;
+      typedef typename __match::__type __type; 
+    };
+
+
+  // Utility for finding the unsigned versions of signed integral types.
+  template<typename _Tp>
+    struct __make_unsigned;
+
+  template<>
+    struct __make_unsigned<char>
+    { typedef unsigned char __type; };
+
+  template<>
+    struct __make_unsigned<signed char>
+    { typedef unsigned char __type; };
+
+  template<>
+    struct __make_unsigned<short>
+    { typedef unsigned short __type; };
+
+  template<>
+    struct __make_unsigned<int>
+    { typedef unsigned int __type; };
+
+  template<>
+    struct __make_unsigned<long>
+    { typedef unsigned long __type; };
+
+  template<>
+    struct __make_unsigned<long long>
+    { typedef unsigned long long __type; };
+
+
+  // Select between integral and enum: not possible to be both.
+  template<typename _Tp, 
+	   bool _IsInt = is_integral<_Tp>::value,
+	   bool _IsEnum = is_enum<_Tp>::value>
+    struct __make_unsigned_selector;
+  
+  template<typename _Tp>
+    struct __make_unsigned_selector<_Tp, true, false>
+    {
+    private:
+      static const bool __b = is_unsigned<_Tp>::value;
+      typedef __make_unsigned<typename remove_cv<_Tp>::type> __unsignedt;
+      typedef typename __unsignedt::__type __unsigned_type;
+      typedef __match_cv_qualifiers<_Tp, __unsigned_type> __cv_unsigned;
+      typedef typename __cv_unsigned::__type __cv_unsigned_type;
+      typedef conditional<__b, _Tp, __cv_unsigned_type> __cond;
+
+    public:
+      typedef typename __cond::type __type;
+    };
+
+  template<typename _Tp>
+    struct __make_unsigned_selector<_Tp, false, true>
+    {
+    private:
+      // GNU enums start with sizeof int.
+      static const bool __b1 = sizeof(_Tp) <= sizeof(unsigned int);
+      static const bool __b2 = sizeof(_Tp) <= sizeof(unsigned long);
+      typedef conditional<__b2, unsigned long, unsigned long long> __cond;
+      typedef typename __cond::type __cond_type;
+      typedef unsigned int __ui_type;
+
+    public:
+      typedef typename conditional<__b1, __ui_type, __cond_type>::type __type;
+    };
+
+
+  // Primary class template.
+  // Given an integral/enum type, return the corresponding unsigned
+  // integer type.
+  // XXX test char/unsigned char/wchar_t unsigned wchar_t, bool, const
+  // int vs const unsigned int
+  template<typename _Tp>
+    struct make_unsigned 
+    { typedef typename __make_unsigned_selector<_Tp>::__type type; };
+
+  // Integral, but don't define.
+  template<>
+    struct make_unsigned<bool>;
+
+  // Integral, but not signed/unsigned.
+  template<>
+    struct make_unsigned<wchar_t>
+    {
+      typedef unsigned wchar_t type;
+    };
+
+
+  // Utility for finding the signed versions of unsigned integral types.
+  template<typename _Tp>
+    struct __make_signed;
+
+  template<>
+    struct __make_signed<char>
+    { typedef signed char __type; };
+
+  template<>
+    struct __make_signed<unsigned char>
+    { typedef signed char __type; };
+
+  template<>
+    struct __make_signed<unsigned short>
+    { typedef signed short __type; };
+
+  template<>
+    struct __make_signed<unsigned int>
+    { typedef signed int __type; };
+
+  template<>
+    struct __make_signed<unsigned long>
+    { typedef signed long __type; };
+
+  template<>
+    struct __make_signed<unsigned long long>
+    { typedef signed long long __type; };
+
+
+  // Select between integral and enum: not possible to be both.
+  template<typename _Tp, 
+	   bool _IsInt = is_integral<_Tp>::value,
+	   bool _IsEnum = is_enum<_Tp>::value>
+    struct __make_signed_selector;
+  
+  template<typename _Tp>
+    struct __make_signed_selector<_Tp, true, false>
+    {
+    private:
+      static const bool __b = is_signed<_Tp>::value;
+      typedef __make_signed<typename remove_cv<_Tp>::type> __signedt;
+      typedef typename __signedt::__type __signed_type;
+      typedef __match_cv_qualifiers<_Tp, __signed_type> __cv_signed;
+      typedef typename __cv_signed::__type __cv_signed_type;
+      typedef conditional<__b, _Tp, __cv_signed_type> __cond;
+
+    public:
+      typedef typename __cond::type __type;
+    };
+
+  template<typename _Tp>
+    struct __make_signed_selector<_Tp, false, true>
+    {
+    private:
+      // GNU enums start with sizeof int.
+      static const bool __b1 = sizeof(_Tp) <= sizeof(signed int);
+      static const bool __b2 = sizeof(_Tp) <= sizeof(signed long);
+      typedef conditional<__b2, signed long, signed long long> __cond;
+      typedef typename __cond::type __cond_type;
+      typedef unsigned int __i_type;
+
+    public:
+      typedef typename conditional<__b1, __i_type, __cond_type>::type __type;
+    };
+
+
+  // Primary class template.
+  // Given an integral/enum type, return the corresponding signed
+  // integer type.
+  // XXX test char/signed char/wchar_t signed wchar_t, bool, const
+  // int vs const signed int
+  template<typename _Tp>
+    struct make_signed 
+    { typedef typename __make_signed_selector<_Tp>::__type type; };
+
+  // Integral, but don't define.
+  template<>
+    struct make_signed<bool>;
+
+  // Integral, but not signed/signed.
+  template<>
+    struct make_signed<wchar_t>
+    {
+      typedef signed wchar_t type;
+    };
+
+_GLIBCXX_END_NAMESPACE
+}
+
 #endif 
 

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