Is it valid, to pass *this to a base class constructor?
template<class Lambda>
struct EmptyL : Lambda
{
EmptyL() : Lambda(*this) //<- is this valid c++?
{ }
};
int main () {
auto l = []() { return 34; };
auto a = EmptyL<decltype(l)>();
return a();
}
EDIT1:
- Why do I do this? Because the ClosureType generated by a lambda expression is not default constructible. And by this "Trick" I am able to default construct such a ClosureType.
- Additionaly the requirements for the template parameter
Lambda
are, that it has to be empty =>static_assert(std::is_empty_v<Lambda>)