請幫我我所面臨的問題,結合...的std :: bind函數採取的std ::的unique_ptr作爲參數
我有一個類成員方法:
std::unique_ptr<TopoDS_Shape> test(std::unique_ptr<TopoDS_Shape> Shape) const
{
std::unique_ptr<TopoDS_Shape> Result = std::make_unique<TopoDS_Shape>();
return(std::move(Result));
}
我需要構建一個std::function
這個指針。爲了做到這一點,我需要使用std::bind
轉發此指針作爲test(...)
是一個類的成員方法:
std::function<std::unique_ptr<TopoDS_Shape>(std::unique_ptr<TopoDS_Shape>)> tTestFunction;
tTestFunction = std::bind(&ComponentModelModifier::test, this, std::placeholders::_1);
然後,的std ::函數指針在我的線程池使用此簽名添加方法:
template<typename FUNCTION, typename... ARGUMENTS>
auto ThreadPool::add(FUNCTION&& Function, ARGUMENTS&&... Arguments) -> std::future<typename std::result_of<FUNCTION(ARGUMENTS...)>::type>
召喚:
std::unique_ptr<TopoDS_Shape> tShape = std::make_unique<TopoDS_Shape>();
ThreadPool tp;
std::future<std::unique_ptr<TopoDS_Shape>> ResultFuture = tp.add(tTestFunction, std::move(tShape));
但構建總是失敗:
error: no type named ‘type’ in ‘class std::result_of<std::reference_wrapper<std::_Bind<std::function<std::unique_ptr<TopoDS_Shape>(std::unique_ptr<TopoDS_Shape>)>(std::unique_ptr<TopoDS_Shape>)> >()>’
typedef typename result_of<_Callable(_Args...)>::type result_type;
我知道std :: unique_ptr不是可複製構造的。這就是爲什麼我試圖使用std :: move但沒有任何工作...
我會很高興任何幫助或踢在正確的方向。提前致謝! Martin
您的函數是否確實接受'std :: unique_ptr Shape' _by value_? –
Petr
我說是的。該函數應該取代用作參數的唯一指針的所有權。我希望你通過測試()... –
這是你的真實代碼嗎? 'reference_wrapper'從哪裏來的? –