4 ms·
> A lambda is both. bool foo() { return [](){return false;}(); } No capture here; no closure. Adding `-O2` to GCC inlines the lambda. > The a
by inetknght 6y ago
> A lambda is both.
bool foo() {
return [](){return false;}();
}
No capture here; no closure. Adding `-O2` to GCC inlines the lambda.
> The amusing thing is that C++ still doesn't have nested functions.
Also amusingly, it does have anonymous types which can have function members.
bool bar() {
struct {
bool orly() {
return false;
}
} a{};
return a.orly();
}
It's fun to send this type of stuff to code review.
Edit: Oh and I forgot; you can refine the member to be static so you don't need to instantiate it first.
bool bar() {
struct a {
static bool orly() {
return false;
}
};
return a::orly();
}
[0] https://gcc.godbolt.org/z/Pjdnre https://gcc.godbolt.org/z/Pjdnre
[1] https://gcc.godbolt.org/z/hc73GP https://gcc.godbolt.org/z/hc73GP