在客户端代码的不同部分同时使用boost::bind和std::tr1::bind

Using both boost::bind and std::tr1::bind in different parts of the client code

本文关键字:bind boost tr1 std 代码 客户端 同部      更新时间:2023-10-16

我使用了两个使用绑定功能的自定义库。其中一个使用std::tr1中的绑定功能,而另一个使用boost bind

现在的问题是关于占位符。由于boost bind的占位符位于未命名的名称空间中,所以当我尝试编译代码时,会遇到以下错误

<file_name.cpp:line_no:char_no>: error: reference to '_1' is ambiguous
/usr/include/c++/4.6/tr1/functional:859:23: error: candidates are: std::tr1::_Placeholder<1> std::tr1::placeholders::{anonymous}::_1
<path>/common/include/boost/bind/placeholders.hpp:55:15: error:                 boost::arg<1> {anonymous}::_1

从我使用的客户端代码中附加仅使用boost绑定功能的行

f_args.f_cb = boost::bind(&MyProcess::flush, MyProcess::Type, _1, _2);

如何解决这个问题?对我来说,对库进行更改或使用不同库的可能性被排除在外。

最终std中的占位符由性状类标识。

代替using namespace占位符,使用traits类使boost占位符变成std占位符。

如果这是不实际的,那么您的boost占位符可能也是如此:为两个占位符创建一组新的占位符令牌,并将其用于两个占位符