Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> 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

[1] https://gcc.godbolt.org/z/hc73GP



Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: