RosettaCodeData/Task/Man-or-boy-test/C++/man-or-boy-test-2.cpp

23 lines
388 B
C++
Raw Permalink Normal View History

2023-07-01 11:58:00 -04:00
#include <functional>
#include <iostream>
2026-04-30 12:34:36 -04:00
typedef std::function_ref<int()> F;
2023-07-01 11:58:00 -04:00
2026-04-30 12:34:36 -04:00
static int A(int k, F x1, F x2, F x3, F x4, F x5)
2023-07-01 11:58:00 -04:00
{
2026-04-30 12:34:36 -04:00
auto B = [&](this const auto& B) -> int {
2023-07-01 11:58:00 -04:00
return A(--k, B, x1, x2, x3, x4);
};
return k <= 0 ? x4() + x5() : B();
}
2026-04-30 12:34:36 -04:00
static auto L(int n)
2023-07-01 11:58:00 -04:00
{
return [n] { return n; };
}
int main()
{
std::cout << A(10, L(1), L(-1), L(-1), L(1), L(0)) << std::endl;
}