I'm having lambdas that don't capture anything, like
[](){};
I have a template class, that contains such a lambda. Since the lambda does not contain non-static data members, nor virtual functions, it should be an empty class and DefaultConstructible. It's only a kind of policy class usable for template metaprogramming. I would like to know, why such a class is not default constructible by the C++ standard.
Sidenote: Understanding how Lambda closure type has deleted default constructor is asking a different question, though the title seems to be very similar. It is asking how a stateless lambda-object is created without usable default constructor. I'm asking why there is no usable default constructor.
[]{}already constructs one and gives you the instance. - rustyxauto f = ()[]{}; using f_t = decltype(f); f_t{};— this works, but for the fact that lambdas have deleted default constructors. - Konrad Rudolphstruct Typename{};is not that much longer than your lambda expression. And it has the added benefits of not creating an object of that type when you're only going to use the type for policies. Lambdas do not exist as a quick means for building structs. - Nicol Bolas