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]: Remove unnecessary overloads in stl_function.h


In stl_function.h, the various mem_fun templates are defined. I was digging through this when I noticed that there was a set of specialised overloads for void. These are noted as only been necessary if the compiler doesn't support partial specialization, and of course g++ does!

The following patch removes the unnessasary overloads and adds a test file.


2005-01-03  Christopher Jefferson <chris@bubblescope.net>

	* include/bits/stl_function.h(mem_fun_t): Remove overload.
	(const_mem_fun_t): Likewise.
	(mem_fun_ref_t): Likewise.
	(const_mem_fun_ref_t): Likewise.
	(mem_fun1_t): Likewise.
	(const_mem_fun1_t): Likewise.
	(mem_fun1_ref_t): Likewise.
	(const_mem_fun1_ref_t): Likewise
	* testsuite/20_util/functional/binders/1.cc: New.
Index: stl_function.h
===================================================================
RCS file: /cvsroot/gcc/gcc/libstdc++-v3/include/bits/stl_function.h,v
retrieving revision 1.18
diff -u -r1.18 stl_function.h
--- stl_function.h	8 Feb 2004 04:46:42 -0000	1.18
+++ stl_function.h	3 Jan 2005 21:46:30 -0000
@@ -566,19 +566,11 @@
 
   // 20.3.8 adaptors pointers members
   /** @defgroup s20_3_8_memadaptors Adaptors for pointers to members
-   *  There are a total of 16 = 2^4 function objects in this family.
+   *  There are a total of 8 = 2^3 function objects in this family.
    *   (1) Member functions taking no arguments vs member functions taking
    *        one argument.
    *   (2) Call through pointer vs call through reference.
-   *   (3) Member function with void return type vs member function with
-   *       non-void return type.
-   *   (4) Const vs non-const member function.
-   *
-   *  Note that choice (3) is nothing more than a workaround: according
-   *   to the draft, compilers should handle void and non-void the same way.
-   *   This feature is not yet widely implemented, though.  You can only use
-   *   member functions returning void if your compiler supports partial
-   *   specialization.
+   *   (3) Const vs non-const member function.
    *
    *  All of this complexity is in the function objects themselves.  You can
    *   ignore it by using the helper function mem_fun and mem_fun_ref,
@@ -714,137 +706,6 @@
       _Ret (_Tp::*_M_f)(_Arg) const;
     };
 
-  /// One of the @link s20_3_8_memadaptors adaptors for member pointers@endlink.
-  template <class _Tp>
-    class mem_fun_t<void, _Tp> : public unary_function<_Tp*, void>
-    {
-    public:
-      explicit
-      mem_fun_t(void (_Tp::*__pf)())
-      : _M_f(__pf) {}
-
-      void
-      operator()(_Tp* __p) const
-      { (__p->*_M_f)(); }
-    private:
-      void (_Tp::*_M_f)();
-    };
-
-  /// One of the @link s20_3_8_memadaptors adaptors for member pointers@endlink.
-  template <class _Tp>
-    class const_mem_fun_t<void, _Tp> : public unary_function<const _Tp*, void>
-    {
-    public:
-      explicit
-      const_mem_fun_t(void (_Tp::*__pf)() const)
-      : _M_f(__pf) {}
-
-      void
-      operator()(const _Tp* __p) const
-      { (__p->*_M_f)(); }
-    private:
-      void (_Tp::*_M_f)() const;
-    };
-
-  /// One of the @link s20_3_8_memadaptors adaptors for member pointers@endlink.
-  template <class _Tp>
-    class mem_fun_ref_t<void, _Tp> : public unary_function<_Tp, void>
-    {
-    public:
-      explicit
-      mem_fun_ref_t(void (_Tp::*__pf)())
-      : _M_f(__pf) {}
-
-      void
-      operator()(_Tp& __r) const
-      { (__r.*_M_f)(); }
-    private:
-      void (_Tp::*_M_f)();
-    };
-
-  /// One of the @link s20_3_8_memadaptors adaptors for member pointers@endlink.
-  template <class _Tp>
-    class const_mem_fun_ref_t<void, _Tp> : public unary_function<_Tp, void>
-    {
-    public:
-      explicit
-      const_mem_fun_ref_t(void (_Tp::*__pf)() const)
-      : _M_f(__pf) {}
-
-      void
-      operator()(const _Tp& __r) const
-      { (__r.*_M_f)(); }
-    private:
-      void (_Tp::*_M_f)() const;
-    };
-
-  /// One of the @link s20_3_8_memadaptors adaptors for member pointers@endlink.
-  template <class _Tp, class _Arg>
-    class mem_fun1_t<void, _Tp, _Arg> : public binary_function<_Tp*, _Arg, void>
-    {
-    public:
-      explicit
-      mem_fun1_t(void (_Tp::*__pf)(_Arg))
-      : _M_f(__pf) {}
-
-      void
-      operator()(_Tp* __p, _Arg __x) const
-      { (__p->*_M_f)(__x); }
-    private:
-      void (_Tp::*_M_f)(_Arg);
-    };
-
-  /// One of the @link s20_3_8_memadaptors adaptors for member pointers@endlink.
-  template <class _Tp, class _Arg>
-    class const_mem_fun1_t<void, _Tp, _Arg>
-    : public binary_function<const _Tp*, _Arg, void>
-    {
-    public:
-      explicit
-      const_mem_fun1_t(void (_Tp::*__pf)(_Arg) const)
-      : _M_f(__pf) {}
-
-      void
-      operator()(const _Tp* __p, _Arg __x) const
-      { (__p->*_M_f)(__x); }
-    private:
-      void (_Tp::*_M_f)(_Arg) const;
-    };
-
-  /// One of the @link s20_3_8_memadaptors adaptors for member pointers@endlink.
-  template <class _Tp, class _Arg>
-    class mem_fun1_ref_t<void, _Tp, _Arg>
-    : public binary_function<_Tp, _Arg, void>
-    {
-    public:
-      explicit
-      mem_fun1_ref_t(void (_Tp::*__pf)(_Arg))
-      : _M_f(__pf) {}
-
-      void
-      operator()(_Tp& __r, _Arg __x) const
-      { (__r.*_M_f)(__x); }
-    private:
-      void (_Tp::*_M_f)(_Arg);
-    };
-
-  /// One of the @link s20_3_8_memadaptors adaptors for member pointers@endlink.
-  template <class _Tp, class _Arg>
-    class const_mem_fun1_ref_t<void, _Tp, _Arg>
-    : public binary_function<_Tp, _Arg, void>
-    {
-    public:
-      explicit
-      const_mem_fun1_ref_t(void (_Tp::*__pf)(_Arg) const)
-      : _M_f(__pf) {}
-
-      void
-      operator()(const _Tp& __r, _Arg __x) const
-      { (__r.*_M_f)(__x); }
-    private:
-      void (_Tp::*_M_f)(_Arg) const;
-    };
-
   // Mem_fun adaptor helper functions.  There are only two:
   // mem_fun and mem_fun_ref.
   template <class _Ret, class _Tp>
// 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.

// 20.3.6 Binders
// { dg-do compile }
#include <functional>
using namespace std;

struct s
{
  void f_void_int_const(int) const {}
  void f_void_int(int) {}
  int f_int_int_const(int) const {}
  int f_int_int(int) {}
  void f_void_void_const() const {}
  void f_void_void() {}
  int f_int_void_const() const {}
  int f_int_void() {}
};

void test01(s& a)
{ 
  mem_fun_t<void,s> p1(&s::f_void_void);
  mem_fun_t<int,s> p2(&s::f_int_void);
  p1(&a);
  p2(&a);
  mem_fun1_t<void,s,int> q1(&s::f_void_int);
  mem_fun1_t<int,s,int> q2(&s::f_int_int);
  q1(&a,0);
  q2(&a,0);

  (mem_fun(&s::f_void_void))(&a);
  (mem_fun(&s::f_void_int))(&a,0);
  (mem_fun(&s::f_int_void))(&a);
  (mem_fun(&s::f_int_int))(&a,0);

  mem_fun_ref_t<void,s> ref1(&s::f_void_void);
  mem_fun_ref_t<int,s> ref2(&s::f_int_void);

  ref1(a);
  ref2(a);

  mem_fun1_ref_t<void,s,int>  ref3(&s::f_void_int);
  mem_fun1_ref_t<int,s,int> ref4(&s::f_int_int); 

  ref3(a,0);
  ref4(a,0);

  (mem_fun_ref(&s::f_void_void))(a);
  (mem_fun_ref(&s::f_void_int))(a,0);
  (mem_fun_ref(&s::f_int_void))(a);
  (mem_fun_ref(&s::f_int_int))(a,0);
}

void test02(const s& a)
{
  const_mem_fun_t<void,s> p1(&s::f_void_void_const);
  const_mem_fun_t<int,s> p2(&s::f_int_void_const);
  p1(&a);
  p2(&a);
  const_mem_fun1_t<void,s,int> q1(&s::f_void_int_const);
  const_mem_fun1_t<int,s,int> q2(&s::f_int_int_const);
  q1(&a,0);
  q2(&a,0);

  (mem_fun(&s::f_void_void_const))(&a);
  (mem_fun(&s::f_void_int_const))(&a,0);
  (mem_fun(&s::f_int_void_const))(&a);
  (mem_fun(&s::f_int_int_const))(&a,0);

  const_mem_fun_ref_t<void,s> ref1(&s::f_void_void_const);
  const_mem_fun_ref_t<int,s> ref2(&s::f_int_void_const);

  ref1(a);
  ref2(a);

  const_mem_fun1_ref_t<void,s,int>  ref3(&s::f_void_int_const);
  const_mem_fun1_ref_t<int,s,int> ref4(&s::f_int_int_const); 

  ref3(a,0);
  ref4(a,0);

  (mem_fun_ref(&s::f_void_void_const))(a);
  (mem_fun_ref(&s::f_void_int_const))(a,0);
  (mem_fun_ref(&s::f_int_void_const))(a);
  (mem_fun_ref(&s::f_int_int_const))(a,0);
}

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