In the code below, in the first form, gcc complains about the presence of lambda in the template parameter. In the second form, gcc complains that lambda_function_pointer has no external connection. Clang compiles and runs the code just fine, even with -pedantic.
+ before lambda is to make it decompose into a function pointer.
template<auto f> void func() { f(); } void g(); int main() { func<+[](){}>();
live: https://godbolt.org/g/ey5uo7
Thanks.
edit: https://timsong-cpp.imtqy.com/cppwp/n4659/expr.prim.lambda#2 mentions lambdas that do not appear in the template parameters, since lambda is not in the signature, but with + it gets rid of lambda- type.
edit2: This may be relevant for the link part of the question: Why does C ++ 03 require that the template parameters have external binding?
c ++ lambda templates
xaxxon
source share