From 542b2507de46567ead65f96d9d3516162c4f37a8 Mon Sep 17 00:00:00 2001 From: Howard Hinnant Date: Tue, 31 May 2011 21:45:26 +0000 Subject: [PATCH] I've seen this question enough times to know that it should be fixed: http://stackoverflow.com/questions/6193734/implicit-conversions-with-stdfunction llvm-svn: 132363 --- libcxx/include/functional | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/libcxx/include/functional b/libcxx/include/functional index 2ea1103f3911..5ee9db23deb1 100644 --- a/libcxx/include/functional +++ b/libcxx/include/functional @@ -1101,6 +1101,21 @@ class _LIBCPP_VISIBLE function<_R(_ArgTypes...)> template _LIBCPP_INLINE_VISIBILITY static bool __not_null(const function<_R(_A...)>& __p) {return __p;} + + template ::value> + struct __callable; + template + struct __callable<_F, true> + { + static const bool value = + is_convertible::type, + _R>::value; + }; + template + struct __callable<_F, false> + { + static const bool value = false; + }; public: typedef _R result_type; @@ -1113,7 +1128,7 @@ public: function(function&&) _NOEXCEPT; template function(_F, - typename enable_if::value>::type* = 0); + typename enable_if<__callable<_F>::value>::type* = 0); template _LIBCPP_INLINE_VISIBILITY @@ -1127,7 +1142,7 @@ public: function(allocator_arg_t, const _Alloc&, function&&); template function(allocator_arg_t, const _Alloc& __a, _F __f, - typename enable_if::value>::type* = 0); + typename enable_if<__callable<_F>::value>::type* = 0); function& operator=(const function&); function& operator=(function&&) _NOEXCEPT; @@ -1135,7 +1150,7 @@ public: template typename enable_if < - !is_integral::type>::value, + __callable::type>::value, function& >::type operator=(_F&&); @@ -1239,7 +1254,7 @@ function<_R(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&, template template function<_R(_ArgTypes...)>::function(_F __f, - typename enable_if::value>::type*) + typename enable_if<__callable<_F>::value>::type*) : __f_(0) { if (__not_null(__f)) @@ -1265,7 +1280,7 @@ function<_R(_ArgTypes...)>::function(_F __f, template template function<_R(_ArgTypes...)>::function(allocator_arg_t, const _Alloc& __a0, _F __f, - typename enable_if::value>::type*) + typename enable_if<__callable<_F>::value>::type*) : __f_(0) { typedef allocator_traits<_Alloc> __alloc_traits; @@ -1341,7 +1356,7 @@ template template typename enable_if < - !is_integral::type>::value, + function<_R(_ArgTypes...)>::template __callable::type>::value, function<_R(_ArgTypes...)>& >::type function<_R(_ArgTypes...)>::operator=(_F&& __f)