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

[v3] tr1/type_traits is_pointer, remove_pointer, add_pointer


Hi,

three more traits + tweaks to the macros, and testcases, of course.

Tested x86-linux.

Paolo.

///////////////
2004-12-12  Paolo Carlini  <pcarlini@suse.de>

	* include/tr1/type_traits: Implement is_pointer, remove_pointer,
	and add_pointer; reformat. 
	(_DEFINE_PRIMARY_SPEC_HELPER, _DEFINE_PRIMARY_SPEC): Generalize
	and rename to _DEFINE_SPEC_HELPER and _DEFINE_SPEC; update uses.
	* testsuite/tr1/4_metaprogramming/pointer_modifications/
	add_pointer.cc: New.
	* testsuite/tr1/4_metaprogramming/pointer_modifications/
	remove_pointer.cc: Likewise.
	* testsuite/tr1/4_metaprogramming/primary_type_categories/
	is_pointer/is_pointer.cc: Likewise.
	* testsuite/tr1/4_metaprogramming/primary_type_categories/
	is_pointer/typedefs.cc: Likewise.

	* testsuite/tr1/4_metaprogramming/primary_type_categories/
	is_reference/is_reference.cc: Slightly tweak consistently.
diff -prN libstdc++-v3-orig/include/tr1/type_traits libstdc++-v3/include/tr1/type_traits
*** libstdc++-v3-orig/include/tr1/type_traits	Sat Dec 11 20:40:13 2004
--- libstdc++-v3/include/tr1/type_traits	Sun Dec 12 15:22:02 2004
*************** namespace tr1
*** 43,91 ****
      };
    typedef integral_constant<bool, true>     true_type;
    typedef integral_constant<bool, false>    false_type;
!   
! #define _DEFINE_PRIMARY_SPEC_HELPER(_Primary, _Type)           \
!   template<>                                                   \
!     struct _Primary<_Type>                                     \
!     : public true_type { };                            
! 
! #define _DEFINE_PRIMARY_SPEC(_Primary, _Type)                  \
!   _DEFINE_PRIMARY_SPEC_HELPER(_Primary, _Type)                 \
!   _DEFINE_PRIMARY_SPEC_HELPER(_Primary, _Type const)           \
!   _DEFINE_PRIMARY_SPEC_HELPER(_Primary, _Type volatile)        \
!   _DEFINE_PRIMARY_SPEC_HELPER(_Primary, _Type const volatile)
!   
    /// @brief  primary type categories [4.5.1].
    template<typename>
      struct is_void
      : public false_type { };
!   _DEFINE_PRIMARY_SPEC(is_void, void)
  
    template<typename>
      struct is_integral
      : public false_type { };
!   _DEFINE_PRIMARY_SPEC(is_integral, bool)
!   _DEFINE_PRIMARY_SPEC(is_integral, char)
!   _DEFINE_PRIMARY_SPEC(is_integral, signed char)
!   _DEFINE_PRIMARY_SPEC(is_integral, unsigned char)
  #ifdef _GLIBCXX_USE_WCHAR_T
!   _DEFINE_PRIMARY_SPEC(is_integral, wchar_t)
  #endif
!   _DEFINE_PRIMARY_SPEC(is_integral, short)
!   _DEFINE_PRIMARY_SPEC(is_integral, unsigned short)
!   _DEFINE_PRIMARY_SPEC(is_integral, int)
!   _DEFINE_PRIMARY_SPEC(is_integral, unsigned int)
!   _DEFINE_PRIMARY_SPEC(is_integral, long)
!   _DEFINE_PRIMARY_SPEC(is_integral, unsigned long)
!   _DEFINE_PRIMARY_SPEC(is_integral, long long)
!   _DEFINE_PRIMARY_SPEC(is_integral, unsigned long long)
  
    template<typename>
      struct is_floating_point
      : public false_type { };
!   _DEFINE_PRIMARY_SPEC(is_floating_point, float)
!   _DEFINE_PRIMARY_SPEC(is_floating_point, double)
!   _DEFINE_PRIMARY_SPEC(is_floating_point, long double)
  
    template<typename>
      struct is_array
--- 43,91 ----
      };
    typedef integral_constant<bool, true>     true_type;
    typedef integral_constant<bool, false>    false_type;
! 
! #define _DEFINE_SPEC_HELPER(_Header, _Spec)                      \
!   template _Header                                               \
!     struct _Spec                                                 \
!     : public true_type { };
!       
! #define _DEFINE_SPEC(_Header, _Primary, _Type)                   \
!   _DEFINE_SPEC_HELPER(_Header, _Primary<_Type>)                  \
!   _DEFINE_SPEC_HELPER(_Header, _Primary<_Type const>)            \
!   _DEFINE_SPEC_HELPER(_Header, _Primary<_Type volatile>)         \
!   _DEFINE_SPEC_HELPER(_Header, _Primary<_Type const volatile>)
! 
    /// @brief  primary type categories [4.5.1].
    template<typename>
      struct is_void
      : public false_type { };
!   _DEFINE_SPEC(<>, is_void, void)
  
    template<typename>
      struct is_integral
      : public false_type { };
!   _DEFINE_SPEC(<>, is_integral, bool)
!   _DEFINE_SPEC(<>, is_integral, char)
!   _DEFINE_SPEC(<>, is_integral, signed char)
!   _DEFINE_SPEC(<>, is_integral, unsigned char)
  #ifdef _GLIBCXX_USE_WCHAR_T
!   _DEFINE_SPEC(<>, is_integral, wchar_t)
  #endif
!   _DEFINE_SPEC(<>, is_integral, short)
!   _DEFINE_SPEC(<>, is_integral, unsigned short)
!   _DEFINE_SPEC(<>, is_integral, int)
!   _DEFINE_SPEC(<>, is_integral, unsigned int)
!   _DEFINE_SPEC(<>, is_integral, long)
!   _DEFINE_SPEC(<>, is_integral, unsigned long)
!   _DEFINE_SPEC(<>, is_integral, long long)
!   _DEFINE_SPEC(<>, is_integral, unsigned long long)
  
    template<typename>
      struct is_floating_point
      : public false_type { };
!   _DEFINE_SPEC(<>, is_floating_point, float)
!   _DEFINE_SPEC(<>, is_floating_point, double)
!   _DEFINE_SPEC(<>, is_floating_point, long double)
  
    template<typename>
      struct is_array
*************** namespace tr1
*** 99,107 ****
      struct is_array<_Tp[]>
      : public true_type { };
    
!   template<typename _Tp>
!     struct is_pointer;
!   
    template<typename>
      struct is_reference
      : public false_type { };
--- 99,109 ----
      struct is_array<_Tp[]>
      : public true_type { };
    
!   template<typename>
!     struct is_pointer
!     : public false_type { };
!   _DEFINE_SPEC(<typename _Tp>, is_pointer, _Tp*)
!  
    template<typename>
      struct is_reference
      : public false_type { };
*************** namespace tr1
*** 128,136 ****
    template<typename _Tp>
      struct is_function;
  
- #undef _DEFINE_PRIMARY_SPEC_HELPER
- #undef _DEFINE_PRIMARY_SPEC
- 
    /// @brief  composite type traits [4.5.2].
    template<typename _Tp>
      struct is_arithmetic
--- 130,135 ----
*************** namespace tr1
*** 266,292 ****
    /// @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
--- 265,283 ----
    /// @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
*************** namespace tr1
*** 307,381 ****
    /// @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;
!     };
    
    template<typename _Tp>
      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>
      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].
    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;
  }
  }
  
--- 298,365 ----
    /// @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; };
    
    template<typename _Tp>
      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>
      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_HELPER
+ #define _DEFINE_SPEC_HELPER(_Header, _Spec)                      \
+   template _Header                                               \
+     struct _Spec                                                 \
+     { typedef _Tp     type; };
+ 
    template<typename _Tp>
!     struct remove_pointer
!     { typedef _Tp     type; };
!   _DEFINE_SPEC(<typename _Tp>, remove_pointer, _Tp*)
    
    template<typename _Tp>
!     struct add_pointer
!     { typedef typename remove_reference<_Tp>::type*     type; };
  
    /// @brief  other transformations [4.8].
    template<std::size_t _Len, std::size_t _Align>
      struct aligned_storage;
+ 
+ #undef _DEFINE_SPEC_HELPER
+ #undef _DEFINE_SPEC
+ 
  }
  }
  
diff -prN libstdc++-v3-orig/testsuite/tr1/4_metaprogramming/pointer_modifications/add_pointer.cc libstdc++-v3/testsuite/tr1/4_metaprogramming/pointer_modifications/add_pointer.cc
*** libstdc++-v3-orig/testsuite/tr1/4_metaprogramming/pointer_modifications/add_pointer.cc	Thu Jan  1 01:00:00 1970
--- libstdc++-v3/testsuite/tr1/4_metaprogramming/pointer_modifications/add_pointer.cc	Sun Dec 12 13:34:20 2004
***************
*** 0 ****
--- 1,46 ----
+ // 2004-12-12  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_pointer;
+   using std::tr1::is_same;
+   using namespace __gnu_test;
+ 
+   VERIFY( (is_same<add_pointer<int>::type, int*>::value) );
+   VERIFY( (is_same<add_pointer<int*>::type, int**>::value) );
+   VERIFY( (is_same<add_pointer<const int>::type, const int*>::value) );
+   VERIFY( (is_same<add_pointer<int&>::type, int*>::value) );
+   VERIFY( (is_same<add_pointer<ClassType*>::type, ClassType**>::value) );
+   VERIFY( (is_same<add_pointer<ClassType>::type, ClassType*>::value) );
+ }
+ 
+ int main()
+ {
+   test01();
+   return 0;
+ }
diff -prN libstdc++-v3-orig/testsuite/tr1/4_metaprogramming/pointer_modifications/remove_pointer.cc libstdc++-v3/testsuite/tr1/4_metaprogramming/pointer_modifications/remove_pointer.cc
*** libstdc++-v3-orig/testsuite/tr1/4_metaprogramming/pointer_modifications/remove_pointer.cc	Thu Jan  1 01:00:00 1970
--- libstdc++-v3/testsuite/tr1/4_metaprogramming/pointer_modifications/remove_pointer.cc	Sun Dec 12 13:36:34 2004
***************
*** 0 ****
--- 1,46 ----
+ // 2004-12-12  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_pointer;
+   using std::tr1::is_same;
+   using namespace __gnu_test;
+ 
+   VERIFY( (is_same<remove_pointer<int*>::type, int>::value) );
+   VERIFY( (is_same<remove_pointer<int>::type, int>::value) );
+   VERIFY( (is_same<remove_pointer<const int*>::type, const int>::value) );
+   VERIFY( (is_same<remove_pointer<int**>::type, int*>::value) );
+   VERIFY( (is_same<remove_pointer<ClassType*>::type, ClassType>::value) );
+   VERIFY( (is_same<remove_pointer<ClassType>::type, ClassType>::value) );
+ }
+ 
+ int main()
+ {
+   test01();
+   return 0;
+ }
diff -prN libstdc++-v3-orig/testsuite/tr1/4_metaprogramming/primary_type_categories/is_pointer/is_pointer.cc libstdc++-v3/testsuite/tr1/4_metaprogramming/primary_type_categories/is_pointer/is_pointer.cc
*** libstdc++-v3-orig/testsuite/tr1/4_metaprogramming/primary_type_categories/is_pointer/is_pointer.cc	Thu Jan  1 01:00:00 1970
--- libstdc++-v3/testsuite/tr1/4_metaprogramming/primary_type_categories/is_pointer/is_pointer.cc	Sun Dec 12 13:11:03 2004
***************
*** 0 ****
--- 1,45 ----
+ // 2004-12-12  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_pointer;
+   using namespace __gnu_test;
+ 
+   VERIFY( (test_category<is_pointer, int*>(true)) );
+   VERIFY( (test_category<is_pointer, ClassType*>(true)) );
+   VERIFY( (test_category<is_pointer, int(*)(int)>(true)) );
+ 
+   // Sanity check.
+   VERIFY( (test_category<is_pointer, ClassType>(false)) );
+ }
+ 
+ int main()
+ {
+   test01();
+   return 0;
+ }
diff -prN libstdc++-v3-orig/testsuite/tr1/4_metaprogramming/primary_type_categories/is_pointer/typedefs.cc libstdc++-v3/testsuite/tr1/4_metaprogramming/primary_type_categories/is_pointer/typedefs.cc
*** libstdc++-v3-orig/testsuite/tr1/4_metaprogramming/primary_type_categories/is_pointer/typedefs.cc	Thu Jan  1 01:00:00 1970
--- libstdc++-v3/testsuite/tr1/4_metaprogramming/primary_type_categories/is_pointer/typedefs.cc	Sun Dec 12 13:04:16 2004
***************
*** 0 ****
--- 1,36 ----
+ // 2004-12-12  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_pointer<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 -prN libstdc++-v3-orig/testsuite/tr1/4_metaprogramming/primary_type_categories/is_reference/is_reference.cc libstdc++-v3/testsuite/tr1/4_metaprogramming/primary_type_categories/is_reference/is_reference.cc
*** libstdc++-v3-orig/testsuite/tr1/4_metaprogramming/primary_type_categories/is_reference/is_reference.cc	Sat Dec 11 21:26:54 2004
--- libstdc++-v3/testsuite/tr1/4_metaprogramming/primary_type_categories/is_reference/is_reference.cc	Sun Dec 12 13:11:49 2004
*************** void test01()
*** 30,42 ****
    using std::tr1::is_reference;
    using namespace __gnu_test;
  
!   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)) );
--- 30,38 ----
    using std::tr1::is_reference;
    using namespace __gnu_test;
  
!   VERIFY( (test_category<is_reference, int&>(true)) );
!   VERIFY( (test_category<is_reference, ClassType&>(true)) );
!   VERIFY( (test_category<is_reference, int(&)(int)>(true)) );
  
    // Sanity check.
    VERIFY( (test_category<is_reference, ClassType>(false)) );

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