나는 생성자에 명명 된 매개 변수를 제공하기 위해 Boost.Parameter 라이브러리를 사용한다.인수를 전달할 때 boost :: ref를 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::ref
에 참조로 통과 할 수 있도록하려는의 boost::function
개체로 복사됩니다.
그러나 boost::ref
이있는 함수 객체를 전달하면 reference_wrapper<T>
이 제거되고 ArgumentPack에 T
값에 대한 참조가 포함됩니다.
질문 :reference_wrapper<T>
래퍼를 제거하지 못하게 할 방법이 있습니까?
예 :
SomeFunctionObject s;
ClassA a(windowFunction = boost::ref(s));
이 SomeFunctionObject& s
이 ClassAImpl
대신 const reference_wrapper<SomeFunctionObject>&
의 생성자에서 mWindowFun
에 전달해야합니다. 따라서 s
은 바람직하지 않은 boost::function
에 의해 복사됩니다.