I just came across a problem to explicit instantiate a templated lambda. The below code does not compile, but I can't figure out what's wrong in this case:
[&]<auto... II>(std::index_sequence<II...>) {
auto check = [&]<auto I>(){
};
(check<II>(),...);
}(std::make_index_sequence<N>{});
Compiler error (gcc trunk: 11.0.0):
rswitch.cc: In lambda function:
rswitch.cc:42:28: error: expected primary-expression before ')' token
42 | (check<II>(),...);
| ^
rswitch.cc:42:26: error: binary expression in operand of fold-expression
42 | (check<II>(),...);
I looks like I had to use the template disambiguation like this:
[&]<auto... II>(std::index_sequence<II...>) {
auto check = [&]<auto I>(){
};
(this->template check<II>(),...);
}(std::make_index_sequence<N>{});
Are there other ways to express this?