2013-03-05 71 views
1

考慮以下函數將函數作爲參數。將std :: forward作爲默認參數傳遞?

template <class Function = std::plus<int> > 
void apply(Function&& f = Function()); 

這裏std::plus<int>是應用的默認功能。 std::plus<int>是一個功能對象,一切正常。

現在,我想通過std::forward<int>作爲默認參數。 std::forward<int>不是函數對象,這是一個函數指針。怎麼做 ?

template <class Function = /* SOMETHING */ > 
void apply(Function&& f = /* SOMETHING */); 

回答

2

我認爲這將工作:

template <class Function = decltype(&std::forward<int>)> 
void apply(Function&& f = &std::forward<int>); 

編輯:實際上,也許不是。你最好只是超載:

void apply() { 
    apply(&std::forward); 
}