名前付きパラメーターをコンストラクターに提供するために、Boost.Parameter ライブラリーを使用します。
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
れます。したがって、コピーされることは望ましくありません。mWindowFun
ClassAImpl
const reference_wrapper<SomeFunctionObject>&
s
boost::function