xcode – c functionalstd :: bind不能用Apple Clang编译

xcode – c functionalstd :: bind不能用Apple Clang编译,第1张

概述这是我尝试编译的代码的简短版本. #include <iostream>#include <functional>#include <memory>void foo(std::shared_ptr<int> b, unsigned int i){ std::cout << *b << " - " << i << std::endl;}int main(){ using n 这是我尝试编译的代码的简短版本.

#include <iostream>#include <functional>#include <memory>voID foo(std::shared_ptr<int> b,unsigned int i){  std::cout << *b << " - " << i << std::endl;}int main(){  using namespace std::placeholders;  typedef std::function<voID(std::shared_ptr<int> b,unsigned int i)> Foo;  typedef std::function<voID(unsigned int code)> bar;  Foo f1 = foo;  bar f2 = std::bind(f1,std::make_shared<int>(10),_1);  f2(0);  return 0;}

g -4.7 –version给出g -4.7(GCC)4.7.1

g++-4.7 -std=c++11 test.cpp && ./a.out10 - 0

c –version给出了Apple clang 4.0版(标签/ Apple / clang-421.0.60)(基于LLVM 3.1svn)

c++ -std=c++11 -stdlib=libc++ test.cppIn file included from test.cpp:3:In file included from /usr/bin/../lib/c++/v1/iostream:38:In file included from /usr/bin/../lib/c++/v1/ios:216:In file included from /usr/bin/../lib/c++/v1/__locale:18:In file included from /usr/bin/../lib/c++/v1/mutex:177:/usr/bin/../lib/c++/v1/functional:1642:8: error: no type named 'type' in 'std::__1::__invoke_of<std::__1::function<voID (std::__1::shared_ptr<int>,unsigned int)> &,std::__1::shared_ptr<int> &,std::__1::shared_ptr<int> &&>'    >::type type;    ~~~^~~~/usr/bin/../lib/c++/v1/functional:1721:18: note: in instantiation of template class 'std::__1::__bind_return<std::__1::function<voID (std::__1::shared_ptr<int>,unsigned int)>,std::__1::tuple<std::__1::shared_ptr<int>,std::__1::placeholders::__ph<1>>,std::__1::tuple<std::__1::shared_ptr<int> &&,unsigned int &&>>' requested here        typename __bind_return<_Fd,_Td,tuple<_Args&&...> >::type                 ^/usr/bin/../lib/c++/v1/functional:1722:9: note: while substituting deduced template arguments into function template 'operator()'      [with _Args = <std::__1::shared_ptr<int>,unsigned int>]        operator()(_Args&& ...__args)        ^/usr/bin/../lib/c++/v1/type_traits:2971:1: note: while substituting deduced template arguments into function template '__invoke' [with _Fp = std::__1::__bind<std::__1::function<voID      (std::__1::shared_ptr<int>,std::__1::shared_ptr<int>,std::__1::placeholders::__ph<1> &> &,_Args = <no value>]__invoke(_Fp&& __f,_Args&& ...__args)^/usr/bin/../lib/c++/v1/type_traits:2989:11: note: in instantiation of template class 'std::__1::__invokable_imp<std::__1::__bind<std::__1::function<voID      (std::__1::shared_ptr<int>,unsigned int>' requested here          __invokable_imp<_Fp,_Args...>::value>          ^/usr/bin/../lib/c++/v1/functional:1115:33: note: in instantiation of template class 'std::__1::__invokable<std::__1::__bind<std::__1::function<voID      (std::__1::shared_ptr<int>,unsigned int>' requested here    template <class _Fp,bool = __invokable<_Fp&,_ArgTypes...>::value>                                ^/usr/bin/../lib/c++/v1/functional:1141:35: note: (skipPing 13 contexts in backtrace; use -ftemplate-backtrace-limit=0 to see all)               typename enable_if<__callable<_Fp>::value>::type* = 0);                                  ^/usr/bin/../lib/c++/v1/memory:2218:20: note: in instantiation of template class 'std::__1::is_nothrow_move_constructible<std::__1::__bind<std::__1::function<voID      (std::__1::shared_ptr<int>,std::__1::placeholders::__ph<1> &>>' requested here        _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value &&                   ^/usr/bin/../lib/c++/v1/__config:253:34: note: expanded from macro '_NOEXCEPT_'#  define _NOEXCEPT_(x) noexcept(x)                                 ^/usr/bin/../lib/c++/v1/memory:2386:15: note: in instantiation of template class 'std::__1::__libcpp_compressed_pair_imp<std::__1::__bind<std::__1::function<voID      (std::__1::shared_ptr<int>,std::__1::placeholders::__ph<1> &>,std::__1::allocator<std::__1::__bind<std::__1::function<voID      (std::__1::shared_ptr<int>,std::__1::placeholders::__ph<1> &>>,2>' requested here    : private __libcpp_compressed_pair_imp<_T1,_T2>              ^/usr/bin/../lib/c++/v1/functional:988:36: note: in instantiation of template class 'std::__1::__compressed_pair<std::__1::__bind<std::__1::function<voID      (std::__1::shared_ptr<int>,std::__1::placeholders::__ph<1> &>>>' requested here    __compressed_pair<_Fp,_Alloc> __f_;                                   ^/usr/bin/../lib/c++/v1/functional:1273:13: note: in instantiation of template class 'std::__1::__function::__func<std::__1::__bind<std::__1::function<voID      (std::__1::shared_ptr<int>,voID (unsigned int)>' requested here        if (sizeof(_FF) <= sizeof(__buf_) && is_nothrow_copy_constructible<_Fp>::value)            ^test.cpp:21:12: note: in instantiation of function template specialization 'std::__1::function<voID (unsigned int)>::function<std::__1::__bind<std::__1::function<voID      (std::__1::shared_ptr<int>,std::__1::placeholders::__ph<1> &> >' requested here  bar f2 = std::bind(f1,_1);           ^1 error generated.

我的代码有问题吗?

谢谢.

解决方法 对此BUG感到抱歉.

这看起来像是一个副本:

http://llvm.org/bugs/show_bug.cgi?id=15295

这是一个修复它的补丁:

Index: include/functional===================================================================--- include/functional  (revision 175515)+++ include/functional  (working copy)@@ -1624,16 +1624,38 @@     : public ____mu_return<_Ti,__is_reference_wrapper<_Ti>::value,is_bind_Expression<_Ti>::value,-                           0 < is_placeholder<_Ti>::value,+                           0 < is_placeholder<_Ti>::value &&+                           is_placeholder<_Ti>::value <= tuple_size<_TupleUj>::value,_TupleUj> { }; template <class _Fp,class _BoundArgs,class _TupleUj>+struct _is_valID_bind_return+{+    static const bool value = false;+};++template <class _Fp,class ..._BoundArgs,class _TupleUj>+struct _is_valID_bind_return<_Fp,tuple<_BoundArgs...>,_TupleUj>+{+    static const bool value = __invokable<_Fp,+                    typename __mu_return<_BoundArgs,_TupleUj>::type...>::value;+};++template <class _Fp,const tuple<_BoundArgs...>,+                    typename __mu_return<const _BoundArgs,class _TupleUj,+          bool = _is_valID_bind_return<_Fp,_BoundArgs,_TupleUj>::value> struct __bind_return; template <class _Fp,class _TupleUj>-struct __bind_return<_Fp,_TupleUj>+struct __bind_return<_Fp,_TupleUj,true> {     typedef typename __invoke_of     <@@ -1647,7 +1669,7 @@ }; template <class _Fp,true> {     typedef typename __invoke_of     <@@ -1673,8 +1695,10 @@ class __bind     : public __weak_result_type<typename decay<_Fp>::type> {+protected:     typedef typename decay<_Fp>::type _Fd;     typedef tuple<typename decay<_BoundArgs>::type...> _Td;+private:     _Fd __f_;     _Td __bound_args_;@@ -1731,7 +1755,7 @@     template <class ..._Args>         _liBCPP_INliNE_VISIBIliTY-        typename __bind_return<_Fd,tuple<_Args&&...> >::type+        typename __bind_return<const _Fd,const _Td,tuple<_Args&&...> >::type         operator()(_Args&& ...__args) const         {             return __apply_functor(__f_,__bound_args_,__indices(),@@ -1747,6 +1771,8 @@     : public __bind<_Fp,_BoundArgs...> {     typedef __bind<_Fp,_BoundArgs...> base;+    typedef typename base::_Fd _Fd;+    typedef typename base::_Td _Td; public:     typedef _Rp result_type;@@ -1784,7 +1810,12 @@     template <class ..._Args>         _liBCPP_INliNE_VISIBIliTY-        result_type+        typename enable_if+        <+            is_convertible<typename __bind_return<_Fd,tuple<_Args&&...> >::type,+                           result_type>::value,+            result_type+        >::type         operator()(_Args&& ...__args)         {             return base::operator()(_VSTD::forward<_Args>(__args)...);@@ -1792,7 +1823,12 @@     template <class ..._Args>         _liBCPP_INliNE_VISIBIliTY-        result_type+        typename enable_if+        <+            is_convertible<typename __bind_return<const _Fd,+            result_type+        >::type         operator()(_Args&& ...__args) const         {             return base::operator()(_VSTD::forward<_Args>(__args)...);
总结

以上是内存溢出为你收集整理的xcode – c functional / std :: bind不能用Apple Clang编译全部内容,希望文章能够帮你解决xcode – c functional / std :: bind不能用Apple Clang编译所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1019182.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-23
下一篇 2022-05-23

发表评论

登录后才能评论

评论列表(0条)

保存