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

Ye but I would just want the possibility for the simpler syntax like the GCC extension for C where you can do:

    typedef void fp_t();
    void foo(fp_t fp)
    {
        fp();
    }

    int square(int num) {

        void square_nested() 
        {
            num = num * num;
        }

        foo(square_nested);

        return num;
    }
That would work as long as you don't need copy capture.


I really don't see how that is so much better than the alternative that it would warrant a language change:

  int square(int num) {
    auto nested = [&num](){ 
       num *= num; 
    };
    nested(num);
    return num;
  }


Slight mistake: should be

    auto nested = [](int& num){
(or switch calling nested to have no params)


The HN C++ compiler ;-)


I agree, given the fact that lambdas are already here.




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

Search: