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]

[Patch] Use variadic templates for tr1::is_function


Hi all, hi Doug,

I'm finishing regtesting the below, which I consider better than instantiating a lot of templates for a single trait and/or using something like the old __in_array. Do you agree?

Besides that, I'm a little puzzled by this kind of code in tr1/functional:

 /**
  * @if maint
  * Retrieve the result type for a function type.
  * @endif
  */
 template<typename _Res, typename... _ArgTypes>
   struct _Weak_result_type_impl<_Res(_ArgTypes...)>
   {
     typedef _Res result_type;
   };

and wanted to quickly double check with you that variadic functions are left out on purpose...

Thanks,
Paolo.

//////////////
2007-04-10  Paolo Carlini  <pcarlini@suse.de>

	* include/tr1/type_traits (is_function): Use variadic templates.
	* testsuite/tr1/4_metaprogramming/primary_type_categories/
	is_function/is_function.cc: Add test.
Index: include/tr1/type_traits
===================================================================
--- include/tr1/type_traits	(revision 123691)
+++ include/tr1/type_traits	(working copy)
@@ -34,6 +34,8 @@
 #ifndef _TR1_TYPE_TRAITS
 #define _TR1_TYPE_TRAITS 1
 
+#pragma GCC system_header
+
 #include <bits/c++config.h>
 #include <tr1/type_traits_fwd.h>
 
@@ -171,16 +173,18 @@
     : public integral_constant<bool, __is_class(_Tp)>
     { };
 
-  template<typename _Tp>
+  template<typename>
     struct is_function
-    : public integral_constant<bool, !(is_void<_Tp>::value
-				       || is_scalar<_Tp>::value
-				       || is_array<_Tp>::value				       
-				       || is_reference<_Tp>::value
-				       || is_union<_Tp>::value
-				       || is_class<_Tp>::value)>
-    { };
+    : public false_type { };
 
+  template<typename _Res, typename... _ArgTypes>
+    struct is_function<_Res(_ArgTypes...)>
+    : public true_type { };
+
+  template<typename _Res, typename... _ArgTypes>
+    struct is_function<_Res(_ArgTypes..., ...)>
+    : public true_type { };
+
   /// @brief  composite type traits [4.5.2].
   template<typename _Tp>
     struct is_arithmetic
Index: testsuite/tr1/4_metaprogramming/primary_type_categories/is_function/is_function.cc
===================================================================
--- testsuite/tr1/4_metaprogramming/primary_type_categories/is_function/is_function.cc	(revision 123691)
+++ testsuite/tr1/4_metaprogramming/primary_type_categories/is_function/is_function.cc	(working copy)
@@ -1,6 +1,6 @@
 // 2004-12-16  Paolo Carlini  <pcarlini@suse.de>
 //
-// Copyright (C) 2004, 2005 Free Software Foundation, Inc.
+// 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
@@ -34,6 +34,7 @@
   VERIFY( (test_category<is_function, int (int)>(true)) );
   VERIFY( (test_category<is_function, ClassType (ClassType)>(true)) );
   VERIFY( (test_category<is_function, float (int, float, int[], int&)>(true)) );
+  VERIFY( (test_category<is_function, int (int, ...)>(true)) );
 
   // Negative tests.
   VERIFY( (test_category<is_function, int&>(false)) );

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