2013-03-05 70 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); 
}