diff options
| author | redi <redi@138bc75d-0d04-0410-961f-82ee72b054a4> | 2012-04-29 22:59:37 +0000 |
|---|---|---|
| committer | redi <redi@138bc75d-0d04-0410-961f-82ee72b054a4> | 2012-04-29 22:59:37 +0000 |
| commit | 3b630ea10b6aaef9f85d08259caf8def31de1902 (patch) | |
| tree | 92006d8b36b05e749a69e1cb31e178739d20de8f /libstdc++-v3/include/std/functional | |
| parent | 86c82b61ccc3aac2f143a169c1f05aa6797d66dd (diff) | |
| download | ppe42-gcc-3b630ea10b6aaef9f85d08259caf8def31de1902.tar.gz ppe42-gcc-3b630ea10b6aaef9f85d08259caf8def31de1902.zip | |
* include/std/functional (function::function(F)): LWG 2132: Disable
constructor if argument isn't callable.
* testsuite/20_util/function/cons/callable.cc: New.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@186947 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libstdc++-v3/include/std/functional')
| -rw-r--r-- | libstdc++-v3/include/std/functional | 40 |
1 files changed, 26 insertions, 14 deletions
diff --git a/libstdc++-v3/include/std/functional b/libstdc++-v3/include/std/functional index 980c6ab40e7..0edb4f1ad33 100644 --- a/libstdc++-v3/include/std/functional +++ b/libstdc++-v3/include/std/functional @@ -1856,7 +1856,7 @@ _GLIBCXX_HAS_NESTED_TYPE(result_type) { typedef _Function_base::_Base_manager<_Functor*> _Base; - public: + public: static bool _M_manager(_Any_data& __dest, const _Any_data& __source, _Manager_operation __op) @@ -1994,7 +1994,7 @@ _GLIBCXX_HAS_NESTED_TYPE(result_type) typedef _Simple_type_wrapper<_Functor> _Wrapper; typedef _Function_base::_Base_manager<_Wrapper> _Base; - public: + public: static bool _M_manager(_Any_data& __dest, const _Any_data& __source, _Manager_operation __op) @@ -2038,7 +2038,23 @@ _GLIBCXX_HAS_NESTED_TYPE(result_type) { typedef _Res _Signature_type(_ArgTypes...); - struct _Useless { }; + template<typename _Functor> + using _Invoke = decltype(__callable_functor(std::declval<_Functor&>()) + (std::declval<_ArgTypes>()...) ); + + template<typename _CallRes, typename _Res1> + struct _CheckResult + : is_convertible<_CallRes, _Res1> { }; + + template<typename _CallRes> + struct _CheckResult<_CallRes, void> + : true_type { }; + + template<typename _Functor> + using _Callable = _CheckResult<_Invoke<_Functor>, _Res>; + + template<typename _Cond, typename _Tp> + using _Requires = typename enable_if<_Cond::value, _Tp>::type; public: typedef _Res result_type; @@ -2099,11 +2115,9 @@ _GLIBCXX_HAS_NESTED_TYPE(result_type) * If @a __f is a non-NULL function pointer or an object of type @c * reference_wrapper<F>, this function will not throw. */ - template<typename _Functor> - function(_Functor __f, - typename enable_if< - !is_integral<_Functor>::value, _Useless>::type - = _Useless()); + template<typename _Functor, + typename = _Requires<_Callable<_Functor>, void>> + function(_Functor); /** * @brief %Function assignment operator. @@ -2178,7 +2192,7 @@ _GLIBCXX_HAS_NESTED_TYPE(result_type) * reference_wrapper<F>, this function will not throw. */ template<typename _Functor> - typename enable_if<!is_integral<_Functor>::value, function&>::type + _Requires<_Callable<_Functor>, function&> operator=(_Functor&& __f) { function(std::forward<_Functor>(__f)).swap(*this); @@ -2187,7 +2201,7 @@ _GLIBCXX_HAS_NESTED_TYPE(result_type) /// @overload template<typename _Functor> - typename enable_if<!is_integral<_Functor>::value, function&>::type + function& operator=(reference_wrapper<_Functor> __f) noexcept { function(__f).swap(*this); @@ -2294,11 +2308,9 @@ _GLIBCXX_HAS_NESTED_TYPE(result_type) } template<typename _Res, typename... _ArgTypes> - template<typename _Functor> + template<typename _Functor, typename> function<_Res(_ArgTypes...)>:: - function(_Functor __f, - typename enable_if< - !is_integral<_Functor>::value, _Useless>::type) + function(_Functor __f) : _Function_base() { typedef _Function_handler<_Signature_type, _Functor> _My_handler; |

