aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3
diff options
context:
space:
mode:
authorDouglas Gregor <doug.gregor@gmail.com>2005-04-02 02:02:29 +0000
committerDoug Gregor <dgregor@gcc.gnu.org>2005-04-02 02:02:29 +0000
commitca6ca8fa9cfa91366a8f5e8cb74b7791777c4eb8 (patch)
treed6eae8dfb0122c33176a1c17449dc631a4b36133 /libstdc++-v3
parent9545f3a9332fae81336a901e3702c1bb92e14e09 (diff)
downloadgcc-ca6ca8fa9cfa91366a8f5e8cb74b7791777c4eb8.zip
gcc-ca6ca8fa9cfa91366a8f5e8cb74b7791777c4eb8.tar.gz
gcc-ca6ca8fa9cfa91366a8f5e8cb74b7791777c4eb8.tar.bz2
functional (_Maybe_wrap_member_pointer): Wrap up member pointers in _Mem_fn but let other function objects pass through...
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. From-SVN: r97428
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 9873fb1..8c4f082 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 ab811d1..abe92e3 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 0a1ccee9..524f2d2 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