From: Douglas Gregor Date: Sat, 2 Apr 2005 02:02:29 +0000 (+0000) Subject: functional (_Maybe_wrap_member_pointer): Wrap up member pointers in _Mem_fn but let... X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=ca6ca8fa9cfa91366a8f5e8cb74b7791777c4eb8;p=gcc.git functional (_Maybe_wrap_member_pointer): Wrap up member pointers in _Mem_fn but let other function objects pass through... 2005-04-01 Douglas Gregor * 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 --- 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 + + * 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 * 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 @@ -659,6 +659,34 @@ namespace tr1 { return __arg; } }; + /** + * @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 + 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 + 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(). 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 -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 -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 -inline _Bind<_Functor(_GLIBCXX_TEMPLATE_ARGS)> +inline +_Bind::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 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