1
如何模板這些函數?在嵌套增強綁定中使用模板函數
boost::function< void(int) > binder(void(*func)(int, char), int a1, char a2)
{
return boost::bind(func, a1, a2);
}
void proxy(boost::function< void(int) > func, int a1)
{
boost::bind(func, a1)();
}
我嘗試沒有成功如下:
template< typename R, typename A1, typename A2 >
static boost::function< void(int) > binder(R(*func)(A1,A2), A1 a1, A2 a2)
{
return boost::bind(func, a1, a2);
}
template< typename A1 >
static void proxy(boost::function< void(A1) > func, A1 a1)
{
boost::bind(func, a1)();
}
這將是很好,如果我可以不用做粘結劑()。這就是我打算如何使用它們:
void print(int i, char c);
boost::signals2::signal.connect(
boost::bind(
&proxy,
boost::bind(
&binder,
&print,
_1,
'a'
),
_1
)
);
我檢查了,沒有運氣以下:
how-to-use-manipulate-return-value-from-nested-boostbind
perform-argument-substitution-on-nested-boostbind-without-composition
can-i-use-boost-bind-with-a-function-template
我申請在發佈代碼的變化。仍然沒有編譯。 – user1005752
@ user1005752:已更新。 –
謝謝。當我推斷出模板參數時,我仍然有點困惑。我會牢記你上面提到的。對信號2部分抱歉。我意識到這一部分,但是試圖「減少」我發佈的代碼。 – user1005752