あなたが何を求めているのか完全にはわかりませんが、突き刺します。
では、std::function
ネストされた が必要ですが、1 回の呼び出しですべての要素を呼び出しますか? これは、いくつかのことを実行できることを意味しますが、最も簡単なのは次のようなものです。
std::function<double(double)> nest(const std::function<double(double)> functions[], const int count) {
if (count == 1) {
return functions[0];
}
return [=](double input) {
return nest(functions + 1, count - 1)(functions[0](input));
};
}
int main()
{
static const auto sq = [](double input) {
return input * input;
};
static const auto dbl_sq = [](double input) {
return sq(input * input);
};
static const auto dbl = [](double input) {
return input * 2;
};
static const std::function<double(double)> sqrt = ::sqrt;
// now lets construct a 'nested lambda'
static const std::function<double(double)> funcs[] = {
sq, dbl, sqrt
};
static const std::function<double(double)> func = nest(funcs, 3);
std::cout << func(4) << std::endl; // 5.65685
std::cout << ::sqrt((4 * 4) * 2) << std::endl; // 5.65685
}
これは、関数の配列を単一の関数に単純に「折りたたむ」ものです。
これがあなたが求めているものでない場合は、元の質問を編集して、達成したいことをより明確にしてください。