Teraz mam następujący zastosować dwie funkcje do wartości i zwracają 2-wartość krotki:Zastosuj krotki funkcji do wartości i powrócić krotki
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_;
};
chciałem generalizować to N funkcje:
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_;
};
Wiem, że prawdopodobnie muszę użyć rekursji szablonów, ale nie mogę owinąć się wokół niego. Jakieś pomysły?
Kolejna praca dla Supermana! Erm, mam na myśli, dla [indeksów] (http://stackoverflow.com/a/10930078/46642). –