如何在boost中使用boost::ref.传递参数时的形参库
How to use boost::ref with Boost.Parameter library when passing arguments?
我使用Boost。为构造函数提供命名参数的参数库。
BOOST_PARAMETER_NAME(windowFunction)
namespace detail
{
struct ClassAImpl
{
template <class ArgumentPack>
ClassAImpl(ArgumentPack const& args)
: mWindowFun(args[_windowFunction])
, [...]
{
}
boost::function<bool(int, int)> mWindowFun;
[...]
};
}
struct ClassA : detail::ClassAImpl
{
BOOST_PARAMETER_CONSTRUCTOR(
ClassA, (detail::ClassAImpl), tag
, (optional (windowFunction,*)
[...]))
};
通常windowFunction
将被boost::function
对象复制,但是我也希望能够通过引用传递boost::ref
。
然而,当我传递boost::ref
函数对象时,reference_wrapper<T>
被删除,ArgumentPack包含对T
值的引用。
问题:是否有办法防止reference_wrapper<T>
包装器的移除?
的例子:
SomeFunctionObject s;
ClassA a(windowFunction = boost::ref(s));
将把SomeFunctionObject& s
传递给ClassAImpl
的构造函数中的mWindowFun
,而不是const reference_wrapper<SomeFunctionObject>&
。因此,s
将被boost::function
复制,这是不希望的。
这似乎目前不可能,因为Boost参数显式地展开reference_wrapper
s。
这是允许通过引用传递位置参数所必需的。
相关文章:
- 泛化传递给 boost::bind 的参数
- boost::p rogram_options 在指定意外的位置参数时不报告任何错误
- 如何通过 boost::p ython 重命名构造函数的关键字参数
- 无法将参数传递给 boost::thread 构造函数
- 在 Windows 中使用 boost::p rogram_options 从命令行参数读取 Unicode 字符
- C++ Boost - 序列化错误 - 将"const B"作为"this"参数
- 如何正确地将 boost::optional<std::chrono::d uration> 作为函数参数?
- Boost::Asio串行读/写打开:参数不正确
- 使用单独的参数调用"boost::process::system()"时,获取"execv
- boost::asio::async_write无效参数
- 在可变参数模板函数中存储参数而不使用 boost::any
- 可变参数宏:重用可变参数(Boost.Fusion)
- boost::p rogram_options 验证每个参数而不是每个参数类型?
- 在 boost::<double>asio::buffer 中使用像 std::vector<std::complex> 这样的参数
- 将 std::bind 应用于带有参数 <boost::asio::ip::tcp::socket> 时出错?
- 如何创建一个版本的 boost::range::transform,该版本具有用于捕获上下文的额外参数
- 如何使用 boost::bind 附加参数?
- 是否可以使用 Boost.Hana 将 std::array 解压缩到非类型模板参数包中
- 参数从 Python 脚本传递到 C++ 使用 boost-python
- 使用强typedef作为Boost参数库的更轻量级的替代方案