▲ 5 r/cpp_questions
can a generic lambda have a value template parameter?
I tried writing some code using generic lambdas, and in my case it would've been useful to have a value parameter for the lambda template. I don't have the code in front of me, but a simplified version had a line like:
auto foo = []<int y>(int x){return x * y;};
I get no compile errors on this line. However, I can't figure out how to provide the value parameter. A line like this gives an error about "no match for the operator '<'".
auto i = foo<5>(3);
If I remove the <5>, then the compiler can't deduce a value for y.
In case it matters, I was trying to use the lambda as a parameter to std::find_if. I've since refactored the code for cleaner logic (also targeting C++ 11, so no generic lambdas now), but I'm curious about whether it should have worked, and if so how.
u/pfp-disciple — 19 hours ago