Hacker News new | past | comments | ask | show | jobs | submit login

Hypothetical nested functions could just use the regular function syntax. Lambdas can be quite a different beast.



gcc has had those (as a non-standard C extension) for a while. Too bad it never made it into the standard.

https://gcc.gnu.org/onlinedocs/gcc/Nested-Functions.html#Nes...


Too bad it would be really nice for sort() etc.


Why would it make a difference? You can pass an anonymous function with two auto arguments as the comparison to sort.


It wouldn't pollute the file scope namespace. You can define it in eye sight of the sort call, steal variables from the nesting functions stack etc.


... but how's that different of what we have today ?

    std::sort(vec.begin(), vec.end(), 
              [] (const auto& lhs, const auto& rhs) { 
      return lhs.whatever < rhs.whatever;
    });
or

    auto sort_by_whatever = [] (const auto& lhs, const auto& rhs) { 
      return lhs.whatever < rhs.whatever;
    };
    std::sort(vec.begin(), vec.end(), sort_by_whatever);


Sorry was refering to C in that comment with no lambdas, with the GCC extension.




Join us for AI Startup School this June 16-17 in San Francisco!

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

Search: