2011-11-10 2 views
1

나는 생성자에 명명 된 매개 변수를 제공하기 위해 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& sClassAImpl 대신 const reference_wrapper<SomeFunctionObject>&의 생성자에서 mWindowFun에 전달해야합니다. 따라서 s은 바람직하지 않은 boost::function에 의해 복사됩니다.

답변

1

부스트 매개 변수가 명시 적으로 reference_wrapper을 래핑하지 않기 때문에 현재로서는 불가능합니다.

이것은 위치 인수를 참조로 전달할 수 있도록하기 위해 필요합니다.

관련 문제