diff options
| author | redi <redi@138bc75d-0d04-0410-961f-82ee72b054a4> | 2011-04-19 13:26:08 +0000 |
|---|---|---|
| committer | redi <redi@138bc75d-0d04-0410-961f-82ee72b054a4> | 2011-04-19 13:26:08 +0000 |
| commit | 409e2405e2f298311e26857cfe610a0865d5d763 (patch) | |
| tree | 46bddda6e0625793f71e6f9abbe316c4f086c355 /libstdc++-v3/include/std/functional | |
| parent | e400b89a267e84f9753ba212b8ec2ce36a5328de (diff) | |
| download | ppe42-gcc-409e2405e2f298311e26857cfe610a0865d5d763.tar.gz ppe42-gcc-409e2405e2f298311e26857cfe610a0865d5d763.zip | |
2011-04-19 Jonathan Wakely <jwakely.gcc@gmail.com>
PR libstdc++/48521
* include/std/type_traits (result_of): Handle pointer to member.
* include/std/functional (__invoke): Likewise.
(_Function_to_function_pointer): Remove.
(_Reference_wrapper_base): Provide nested types independent of
unary_function and binary_function.
(reference_wrapper::operator()): DR 2017.
(ref(const A&&), cref(const A&&): Define as deleted.
* include/std/future (async): Simplify SFINAE and use result_of to
support pointer to member.
* testsuite/20_util/reference_wrapper/invoke.cc: Test pointer to
member.
* testsuite/20_util/reference_wrapper/24803.cc: Likewise.
* testsuite/20_util/reference_wrapper/typedefs.cc: Test for types
instead of derivation from unary_function and binary_function.
* testsuite/20_util/declval/requirements/1_neg.cc: Adjust.
* testsuite/20_util/reference_wrapper/invoke-2.cc: New.
* testsuite/20_util/reference_wrapper/ref_neg.c: New.
* testsuite/20_util/reference_wrapper/typedefs-3.c: New.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@172709 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libstdc++-v3/include/std/functional')
| -rw-r--r-- | libstdc++-v3/include/std/functional | 88 |
1 files changed, 47 insertions, 41 deletions
diff --git a/libstdc++-v3/include/std/functional b/libstdc++-v3/include/std/functional index 660e371b599..57ec5062133 100644 --- a/libstdc++-v3/include/std/functional +++ b/libstdc++-v3/include/std/functional @@ -212,19 +212,6 @@ _GLIBCXX_HAS_NESTED_TYPE(result_type) static const bool value = sizeof(__test((_Tp*)0)) == 1; }; - /// Turns a function type into a function pointer type - template<typename _Tp, bool _IsFunctionType = is_function<_Tp>::value> - struct _Function_to_function_pointer - { - typedef _Tp type; - }; - - template<typename _Tp> - struct _Function_to_function_pointer<_Tp, true> - { - typedef _Tp* type; - }; - /** * Invoke a function object, which may be either a member pointer or a * function object. The first parameter will tell which. @@ -235,20 +222,33 @@ _GLIBCXX_HAS_NESTED_TYPE(result_type) (!is_member_pointer<_Functor>::value && !is_function<_Functor>::value && !is_function<typename remove_pointer<_Functor>::type>::value), - typename result_of<_Functor(_Args...)>::type + typename result_of<_Functor(_Args&&...)>::type >::type __invoke(_Functor& __f, _Args&&... __args) { return __f(std::forward<_Args>(__args)...); } + template<typename _Functor, typename... _Args> + inline + typename enable_if< + (is_member_pointer<_Functor>::value + && !is_function<_Functor>::value + && !is_function<typename remove_pointer<_Functor>::type>::value), + typename result_of<_Functor(_Args&&...)>::type + >::type + __invoke(_Functor& __f, _Args&&... __args) + { + return mem_fn(__f)(std::forward<_Args>(__args)...); + } + // To pick up function references (that will become function pointers) template<typename _Functor, typename... _Args> inline typename enable_if< (is_pointer<_Functor>::value && is_function<typename remove_pointer<_Functor>::type>::value), - typename result_of<_Functor(_Args...)>::type + typename result_of<_Functor(_Args&&...)>::type >::type __invoke(_Functor __f, _Args&&... __args) { @@ -263,40 +263,43 @@ _GLIBCXX_HAS_NESTED_TYPE(result_type) template<bool _Unary, bool _Binary, typename _Tp> struct _Reference_wrapper_base_impl; - // Not a unary_function or binary_function, so try a weak result type. + // None of the nested argument types. template<typename _Tp> struct _Reference_wrapper_base_impl<false, false, _Tp> : _Weak_result_type<_Tp> { }; - // unary_function but not binary_function + // Nested argument_type only. template<typename _Tp> struct _Reference_wrapper_base_impl<true, false, _Tp> - : unary_function<typename _Tp::argument_type, - typename _Tp::result_type> - { }; + : _Weak_result_type<_Tp> + { + typedef typename _Tp::argument_type argument_type; + }; - // binary_function but not unary_function + // Nested first_argument_type and second_argument_type only. template<typename _Tp> struct _Reference_wrapper_base_impl<false, true, _Tp> - : binary_function<typename _Tp::first_argument_type, - typename _Tp::second_argument_type, - typename _Tp::result_type> - { }; + : _Weak_result_type<_Tp> + { + typedef typename _Tp::first_argument_type first_argument_type; + typedef typename _Tp::second_argument_type second_argument_type; + }; - // Both unary_function and binary_function. Import result_type to - // avoid conflicts. + // All the nested argument types. template<typename _Tp> struct _Reference_wrapper_base_impl<true, true, _Tp> - : unary_function<typename _Tp::argument_type, - typename _Tp::result_type>, - binary_function<typename _Tp::first_argument_type, - typename _Tp::second_argument_type, - typename _Tp::result_type> + : _Weak_result_type<_Tp> { - typedef typename _Tp::result_type result_type; + typedef typename _Tp::argument_type argument_type; + typedef typename _Tp::first_argument_type first_argument_type; + typedef typename _Tp::second_argument_type second_argument_type; }; + _GLIBCXX_HAS_NESTED_TYPE(argument_type) + _GLIBCXX_HAS_NESTED_TYPE(first_argument_type) + _GLIBCXX_HAS_NESTED_TYPE(second_argument_type) + /** * Derives from unary_function or binary_function when it * can. Specializations handle all of the easy cases. The primary @@ -306,8 +309,9 @@ _GLIBCXX_HAS_NESTED_TYPE(result_type) template<typename _Tp> struct _Reference_wrapper_base : _Reference_wrapper_base_impl< - _Derives_from_unary_function<_Tp>::value, - _Derives_from_binary_function<_Tp>::value, + __has_argument_type<_Tp>::value, + __has_first_argument_type<_Tp>::value + && __has_second_argument_type<_Tp>::value, _Tp> { }; @@ -422,12 +426,8 @@ _GLIBCXX_HAS_NESTED_TYPE(result_type) class reference_wrapper : public _Reference_wrapper_base<typename remove_cv<_Tp>::type> { - // If _Tp is a function type, we can't form result_of<_Tp(...)>, - // so turn it into a function pointer type. - typedef typename _Function_to_function_pointer<_Tp>::type - _M_func_type; - _Tp* _M_data; + public: typedef _Tp type; @@ -456,7 +456,7 @@ _GLIBCXX_HAS_NESTED_TYPE(result_type) { return *_M_data; } template<typename... _Args> - typename result_of<_M_func_type(_Args...)>::type + typename result_of<_Tp&(_Args&&...)>::type operator()(_Args&&... __args) const { return __invoke(get(), std::forward<_Args>(__args)...); @@ -476,6 +476,12 @@ _GLIBCXX_HAS_NESTED_TYPE(result_type) cref(const _Tp& __t) { return reference_wrapper<const _Tp>(__t); } + template<typename _Tp> + void ref(const _Tp&&) = delete; + + template<typename _Tp> + void cref(const _Tp&&) = delete; + /// Partial specialization. template<typename _Tp> inline reference_wrapper<_Tp> |

