6
,我有以下的申請兩個函數的值,並返回一個2值元組:應用功能的元組的值,現在返回一個元組
template<typename F1, typename F2>
class Apply2
{
public:
using return_type = std::tuple<typename F1::return_type, typename F2::return_type>;
Apply2(const F1& f1, const F2& f2) : f1_(f1), f2_(f2) {}
template<typename T> return_type operator()(const T& t) const
{
return std::make_tuple(f1_(t), f2_(t));
}
protected:
const F1& f1_;
const F2& f2_;
};
我想概括這N函數:
template<typename ...F>
class ApplyN
{
public:
using return_type = std::tuple<typename F::return_type...>;
ApplyN(const std::tuple<F...>& fs) : functions_(fs) {}
template<typename T> return_type operator()(const T& t) const
{
return ???;
}
protected:
std::tuple<F...> functions_;
};
我知道我可能需要使用模板遞歸莫名其妙,但我不能包裹我的頭。有任何想法嗎?
超人又一份工作!嗯,我的意思是,[索引](http://stackoverflow.com/a/10930078/46642)。 –