First, the lambda is:
[](...){}
This is a lambda that captures nothing, has an empty function block, the {}, and uses a C style variadic function parameter to accept any number of parameters.
The whole:
[](...){}(n3, n4, x, r2);
Is what is known as an "immediately invoked lambda expression", as you define the lambda and call it at the same time. The call is the (n3, n4, x, r2), where those 4 variables are passed to the lambda, and nothing happens since the lambda has an empty function block.
To see an actual use case, instead of having to write:
template<typename Tuple, typename Function, std::size_t... Is>
void tuple_for_each_impl(const Tuple& tup, Function func, std::index_sequence<Is...>)
{
(func(std::get<Is>(tup)), ...);
}
template<typename... Ts, typename Function>
void tuple_for_each(const std::tuple<Ts...>& tup, Function func)
{
tuple_for_each_impl(tup, func, std::make_index_sequence<sizeof...(Ts)>{});
}
to make a for_each for a tuple, you can instead use:
template<typename... Ts, typename Function>
void tuple_for_each(const std::tuple<Ts...>& tup, Function func)
{
[&]<std::size_t... Is>(std::index_sequence<Is...>)
{
(func(std::get<Is>(tup)), ...);
}(std::make_index_sequence<sizeof...(Ts)>{});
}