This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
[Patch] Port from v7 stl_function clean-up
- From: Paolo Carlini <pcarlini at suse dot de>
- To: libstdc++ <libstdc++ at gcc dot gnu dot org>
- Date: Thu, 16 Jun 2005 17:57:17 +0200
- Subject: [Patch] Port from v7 stl_function clean-up
Hi,
another small change that we applied to v7-branch only but seems
definitely safe for mainline too.
I'm finishing testing on x86-linux, will wait a while in case of issues.
Paolo.
///////////////
2005-06-17 Paolo Carlini <pcarlini@suse.de>
Port from libstdcxx_so_7-branch:
2005-01-12 Christopher Jefferson <chris@bubblescope.net>
* include/bits/stl_function.h (mem_fun_t, const_mem_fun_t,
mem_fun_ref_t, const_mem_fun_ref_t, mem_fun1_t, const_mem_fun1_t,
mem_fun1_ref_t, const_mem_fun1_ref_t): Remove overloads for void
return type, just an old HP/SGI workaround.
* testsuite/20_util/functional/binders.cc: Move to...
* testsuite/20_util/functional/binders/3113.cc: ...here.
* testsuite/20_util/functional/binders/1.cc: New.
diff -urN libstdc++-v3-orig/include/bits/stl_function.h libstdc++-v3/include/bits/stl_function.h
--- libstdc++-v3-orig/include/bits/stl_function.h 2005-06-06 12:00:34.000000000 +0200
+++ libstdc++-v3/include/bits/stl_function.h 2005-06-16 17:41:54.000000000 +0200
@@ -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>
diff -urN libstdc++-v3-orig/testsuite/20_util/functional/binders/1.cc libstdc++-v3/testsuite/20_util/functional/binders/1.cc
--- libstdc++-v3-orig/testsuite/20_util/functional/binders/1.cc 1970-01-01 01:00:00.000000000 +0100
+++ libstdc++-v3/testsuite/20_util/functional/binders/1.cc 2005-06-16 17:45:40.000000000 +0200
@@ -0,0 +1,104 @@
+// 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);
+}
diff -urN libstdc++-v3-orig/testsuite/20_util/functional/binders/3113.cc libstdc++-v3/testsuite/20_util/functional/binders/3113.cc
--- libstdc++-v3-orig/testsuite/20_util/functional/binders/3113.cc 1970-01-01 01:00:00.000000000 +0100
+++ libstdc++-v3/testsuite/20_util/functional/binders/3113.cc 2005-03-16 12:24:14.000000000 +0100
@@ -0,0 +1,50 @@
+// 2001-06-11 Benjamin Kosnik <bkoz@redhat.com>
+
+// Copyright (C) 2001, 2003, 2004, 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
+
+#include <vector>
+#include <algorithm> // for_each
+#include <functional>
+
+class Elem
+{
+public:
+ void print(int) const { }
+ void modify(int) { }
+};
+
+// libstdc++/3113
+void test01()
+{
+ std::vector<Elem> coll(2);
+ // OK
+ std::for_each(coll.begin(), coll.end(),
+ std::bind2nd(std::mem_fun_ref(&Elem::print), 42));
+ // OK
+ std::for_each(coll.begin(), coll.end(),
+ std::bind2nd(std::mem_fun_ref(&Elem::modify), 42));
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff -urN libstdc++-v3-orig/testsuite/20_util/functional/binders.cc libstdc++-v3/testsuite/20_util/functional/binders.cc
--- libstdc++-v3-orig/testsuite/20_util/functional/binders.cc 2005-03-16 12:24:14.000000000 +0100
+++ libstdc++-v3/testsuite/20_util/functional/binders.cc 1970-01-01 01:00:00.000000000 +0100
@@ -1,50 +0,0 @@
-// 2001-06-11 Benjamin Kosnik <bkoz@redhat.com>
-
-// Copyright (C) 2001, 2003, 2004, 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
-
-#include <vector>
-#include <algorithm> // for_each
-#include <functional>
-
-class Elem
-{
-public:
- void print(int) const { }
- void modify(int) { }
-};
-
-// libstdc++/3113
-void test01()
-{
- std::vector<Elem> coll(2);
- // OK
- std::for_each(coll.begin(), coll.end(),
- std::bind2nd(std::mem_fun_ref(&Elem::print), 42));
- // OK
- std::for_each(coll.begin(), coll.end(),
- std::bind2nd(std::mem_fun_ref(&Elem::modify), 42));
-}
-
-int main()
-{
- test01();
- return 0;
-}