u/pfp-disciple

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&lt;5&gt;(3);

If I remove the &lt;5&gt;, 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.

reddit.com
u/pfp-disciple — 19 hours ago