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
Qoto Mastodon

QOTO: Question Others to Teach Ourselves
An inclusive, Academic Freedom, instance
All cultures welcome.
Hate speech and harassment strictly forbidden.