Follow

Как-то всё обходил меня стороной возможный рекурсивный вызов лямбды в C++, благодаря generic lambda expression (который давно уже появился, начиная с C++14):

<iostream>
<string>

int main()
{
auto print_star = [](int n, const auto& f) -> void {
std::cout << std::string(n, '*') << std::endl;
if (n-- > 1)
{
f(n, f);
}
};
print_star(5, print_star);
return 0;
}

Вывод:
*****
****
***
**
*

Sign in to participate in the conversation
CleverLibre Social

CleverLibre Social is an inclusive social instance for open discussion, learning, and community.
All cultures welcome.
Hate speech and harassment strictly forbidden.