summaryrefslogtreecommitdiff
path: root/libstdc++-v3
diff options
context:
space:
mode:
authordgregor <dgregor@138bc75d-0d04-0410-961f-82ee72b054a4>2005-04-02 02:02:29 +0000
committerdgregor <dgregor@138bc75d-0d04-0410-961f-82ee72b054a4>2005-04-02 02:02:29 +0000
commit2fce8e25a22978c057944764adcbb69da98ae010 (patch)
treed6eae8dfb0122c33176a1c17449dc631a4b36133 /libstdc++-v3
parent4876d8f7c009fb2acf5359cdaaa6aa77c0b90166 (diff)
downloadgcc-2fce8e25a22978c057944764adcbb69da98ae010.tar.gz
2005-04-01 Douglas Gregor <doug.gregor@gmail.com>
* include/tr1/functional (_Maybe_wrap_member_pointer): Wrap up member pointers in _Mem_fn but let other function objects pass through unchanged. * include/tr1/functional_iterator (bind): Reduce number of bind() overloads to two to eliminate ambiguities. Use _Maybe_wrap_member_pointer to handle member pointers gracefully. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@97428 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libstdc++-v3')
-rw-r--r--libstdc++-v3/ChangeLog9
-rw-r--r--libstdc++-v3/include/tr1/functional28
-rw-r--r--libstdc++-v3/include/tr1/functional_iterate.h44
3 files changed, 53 insertions, 28 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index 9873fb170d9..8c4f0821f56 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,3 +1,12 @@
+2005-04-01 Douglas Gregor <doug.gregor@gmail.com>
+
+ * include/tr1/functional (_Maybe_wrap_member_pointer): Wrap up
+ member pointers in _Mem_fn but let other function objects pass
+ through unchanged.
+ * include/tr1/functional_iterator (bind): Reduce number of bind()
+ overloads to two to eliminate ambiguities. Use
+ _Maybe_wrap_member_pointer to handle member pointers gracefully.
+
2005-04-01 Mark Mitchell <mark@codesourcery.com>
* testsuite/Makefile.am (noinst_PROGRAMS): Remove.
diff --git a/libstdc++-v3/include/tr1/functional b/libstdc++-v3/include/tr1/functional
index ab811d1c8a6..abe92e3bf23 100644
--- a/libstdc++-v3/include/tr1/functional
+++ b/libstdc++-v3/include/tr1/functional
@@ -661,6 +661,34 @@ namespace tr1
/**
* @if maint
+ * Maps member pointers into instances of _Mem_fn but leaves all
+ * other function objects untouched. Used by tr1::bind(). The
+ * primary template handles the non--member-pointer case.
+ * @endif
+ */
+ template<typename _Tp>
+ struct _Maybe_wrap_member_pointer
+ {
+ typedef _Tp type;
+ static const _Tp& __do_wrap(const _Tp& __x) { return __x; }
+ };
+
+ /**
+ * @if maint
+ * Maps member pointers into instances of _Mem_fn but leaves all
+ * other function objects untouched. Used by tr1::bind(). This
+ * partial specialization handles the member pointer case.
+ * @endif
+ */
+ template<typename _Tp, typename _Class>
+ struct _Maybe_wrap_member_pointer<_Tp _Class::*>
+ {
+ typedef _Mem_fn<_Tp _Class::*> type;
+ static type __do_wrap(_Tp _Class::* __pm) { return type(__pm); }
+ };
+
+ /**
+ * @if maint
* Type of the function object returned from bind().
* @endif
*/
diff --git a/libstdc++-v3/include/tr1/functional_iterate.h b/libstdc++-v3/include/tr1/functional_iterate.h
index 0a1ccee94e8..524f2d2be19 100644
--- a/libstdc++-v3/include/tr1/functional_iterate.h
+++ b/libstdc++-v3/include/tr1/functional_iterate.h
@@ -444,46 +444,34 @@ class _Bind_result<_Result, _Functor(_GLIBCXX_TEMPLATE_ARGS)>
#undef _GLIBCXX_BIND_REPEAT_HEADER
};
-// Handle member pointers
-template<typename _Tp, typename _Class _GLIBCXX_COMMA _GLIBCXX_TEMPLATE_PARAMS>
-inline _Bind<_Mem_fn<_Tp _Class::*>(_GLIBCXX_TEMPLATE_ARGS)>
-bind(_Tp _Class::* __pm _GLIBCXX_COMMA _GLIBCXX_PARAMS)
-{
- typedef _Bind<_Mem_fn<_Tp _Class::*>(_GLIBCXX_TEMPLATE_ARGS)> __result_type;
- return __result_type(_Mem_fn<_Tp _Class::*>(__pm)
- _GLIBCXX_COMMA _GLIBCXX_ARGS);
-}
-
-template<typename _Result, typename _Tp, typename _Class
- _GLIBCXX_COMMA _GLIBCXX_TEMPLATE_PARAMS>
-inline _Bind_result<_Result, _Mem_fn<_Tp _Class::*>(_GLIBCXX_TEMPLATE_ARGS)>
-bind(_Tp _Class::* __pm _GLIBCXX_COMMA _GLIBCXX_PARAMS)
-{
- typedef _Bind_result<_Result, _Mem_fn<_Tp _Class::*>(_GLIBCXX_TEMPLATE_ARGS)>
- __result_type;
- return __result_type(_Mem_fn<_Tp _Class::*>(__pm)
- _GLIBCXX_COMMA _GLIBCXX_ARGS);
-}
-
// Handle arbitrary function objects
template<typename _Functor _GLIBCXX_COMMA _GLIBCXX_TEMPLATE_PARAMS>
-inline _Bind<_Functor(_GLIBCXX_TEMPLATE_ARGS)>
+inline
+_Bind<typename _Maybe_wrap_member_pointer<_Functor>::type
+ (_GLIBCXX_TEMPLATE_ARGS)>
bind(_Functor __f _GLIBCXX_COMMA _GLIBCXX_PARAMS)
{
- typedef _Bind<_Functor(_GLIBCXX_TEMPLATE_ARGS)> __result_type;
- return __result_type(__f _GLIBCXX_COMMA _GLIBCXX_ARGS);
+ typedef _Maybe_wrap_member_pointer<_Functor> __maybe_type;
+ typedef typename __maybe_type::type __functor_type;
+ typedef _Bind<__functor_type(_GLIBCXX_TEMPLATE_ARGS)> __result_type;
+ return __result_type(__maybe_type::__do_wrap(__f)
+ _GLIBCXX_COMMA _GLIBCXX_ARGS);
}
template<typename _Result, typename _Functor
_GLIBCXX_COMMA _GLIBCXX_TEMPLATE_PARAMS>
inline
-typename __enable_if<_Bind_result<_Result, _Functor(_GLIBCXX_TEMPLATE_ARGS)>,
- !is_member_pointer<_Functor>::value>::__type
+_Bind_result<_Result,
+ typename _Maybe_wrap_member_pointer<_Functor>::type
+ (_GLIBCXX_TEMPLATE_ARGS)>
bind(_Functor __f _GLIBCXX_COMMA _GLIBCXX_PARAMS)
{
- typedef _Bind_result<_Result, _Functor(_GLIBCXX_TEMPLATE_ARGS)>
+ typedef _Maybe_wrap_member_pointer<_Functor> __maybe_type;
+ typedef typename __maybe_type::type __functor_type;
+ typedef _Bind_result<_Result, __functor_type(_GLIBCXX_TEMPLATE_ARGS)>
__result_type;
- return __result_type(__f _GLIBCXX_COMMA _GLIBCXX_ARGS);
+ return __result_type(__maybe_type::__do_wrap(__f)
+ _GLIBCXX_COMMA _GLIBCXX_ARGS);
}
template<typename _Res, typename _Functor _GLIBCXX_COMMA