Lambda expressions are not allowed in unappraised contexts (for example, decltype) and cannot be constant expressions until recently. Therefore, it was not possible to use them in the template arguments.
In C ++ 17, a constant lambdas expression is possible. This still prevents them from being used in template arguments at all.
However, specifically for template arguments without a type, a constant expression lambda expressions can be used in the evaluated context, for example:
template<int N> struct S { constexpr static int value = N; }; int main() { int N = S<[]()constexpr{return 42;}()>::value; }
This still does not work, because lambda expressions are explicitly forbidden in the template arguments, whether type or non-type.
My question is a reasoning that does not allow to build higher. I can understand that lambdas types in function signatures can be problematic, but here the closure type does not matter, only the return value is used (compile-time constant).
I suspect that the reason is that all statements in the lambda body will become part of the expression of the template argument, and therefore SFINAE will need to be applied if any statement in the body is poorly formed during the replacement. This will probably require considerable work from compiler developers.
But this is actually my motivation. If one could use the construction above, then SFINAE could be used not only with constant expressions, but also with other operators valid in constexpr-functions (for example, declarations of the literal type).
Besides the impact on the authors of the compiler, are there any problems that might cause, for example. ambiguities, contradictions, or complications in the standard?