c++ - 绑定(bind)对象未在 VS2015 上编译

标签 c++ boost boost-asio visual-studio-2015 libtorrent

libtorrent 中,我发现了以下代码,它不能用 Visual Studio 2015 RC 编译:

boost::bind( &address::is_v4,
             boost::bind( &tcp::endpoint::address,
                          _1
             )
)
== m_bind_addr.is_v4()

虽然我们可能会争论使用 bind 运算符重载的问题,但我实际上想知道,为什么它不能编译。错误信息是:

C:\Projects\boost\boost/bind/bind.hpp(2003): error C2027: use of undefined type 'boost::_bi::add_cref<Pm,0>'
          with
          [
              Pm=bool (__thiscall boost::asio::ip::address::* )(void) const
          ]
  C:\Projects\boost\boost/bind/bind.hpp(2011): note: see reference to class template instantiation 'boost::_bi::dm_result<M (__thiscall boost::asio::ip::address::* ),A1>' being compiled
          with
          [
              M=bool (void) const,
              A1=boost::_bi::bind_t<boost::asio::ip::address,boost::_mfi::cmf0<boost::asio::ip::address,boost::asio::ip::basic_endpoint<boost::asio::ip::tcp>>,boost::_bi::list1<boost::arg<1>>>
          ]

最佳答案

我遇到了这个,但只针对 32 位编译。 64 位很好。用 mem_fn(来自 boost/mem_fn.hpp)包围函数就可以了:

boost::bind( &address::is_v4,
         boost::bind( boost::mem_fn( &tcp::endpoint::address),
                      _1
         )
) == m_bind_addr.is_v4()

关于c++ - 绑定(bind)对象未在 VS2015 上编译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30168213/

相关文章:

c++ - `enable_shared_from_this` 有什么用处?

c++ - 编译没有对应头文件的cpp

c++ - 创建一个安全的转义路径基/文件名,检查是否安全

c++ - 为什么在 std::variant 中禁止引用?

c++ - boost::asio::io_service 是否保留处理程序的顺序?

c++ - 使用 async_write 同时写入不同的套接字

c++ - 禁用/覆盖 -Werror=sign-compare

c++ - 在只有模板化返回类型的函数模板中混合模板特化和 enable_if

c++ - 检索数组最干净的方法是什么?

boost - 如何使用 boost mpi 传递用户定义的结构