[c++] lambda递归

/ 870评论 / 3825阅读 / 0点赞

lambda表达式

int main() {
    // 声明
    auto fun = []() {
        cout << 123 << endl;
    };
    // 调用
    fun();
    return 0;
}

递归

int hello(int value) {
    if(value < 0) {
        return 0;
    }
    cout << value << endl;
    hello(value - 1);
}

lambda递归

int main() {
    auto fun = [&fun](int value) {
        if(value < 0) { 
             return;
        }
        cout << value << endl;
        // 这里是不行的!!!
        fun(value - 1);
    };
    fun(10);
    return 0;
}

#include <iostream>
#include <functional>
using namespace std;

int main() {
    int i = 10;
    std::function<void()> myfun;
    myfun = [&myfun, &i]() {
        if (i < 0) {
            return;
        }
        cout << i << endl;
        --i;
        myfun();
    };
    myfun();
    return 0;
}
  1. RobertLAr说道:

    buy cipro online without prescription: antibiotics cipro – buy cipro no rx

  2. door closer说道:

    I quite like reading through an article that can make people think. Also, thank you for allowing me to comment.

  3. sex说道:

    I absolutely love your website.. Great colors & theme. Did you create this web site yourself? Please reply back as I’m planning to create my very own blog and would love to find out where you got this from or what the theme is called. Many thanks!

  4. porn说道:

    Having read this I thought it was extremely informative. I appreciate you taking the time and effort to put this information together. I once again find myself spending way too much time both reading and leaving comments. But so what, it was still worthwhile.

  5. discover here说道:

    Spot on with this write-up, I seriously feel this amazing site needs a great deal more attention. I’ll probably be returning to see more, thanks for the advice!

  6. Way cool! Some extremely valid points! I appreciate you penning this write-up and the rest of the site is extremely good.

  7. Everything is very open with a really clear description of the challenges. It was really informative. Your site is extremely helpful. Many thanks for sharing!

  8. Alicia说道:

    An interesting discussion is worth comment. I believe that you should publish more on this subject matter, it might not be a taboo matter but usually people do not talk about these issues. To the next! All the best!

  9. 6789bet说道:

    I like it when individuals come together and share views. Great website, keep it up.

  10. 789b1 com说道:

    Hi there! This blog post couldn’t be written much better! Going through this article reminds me of my previous roommate! He always kept preaching about this. I’ll forward this post to him. Fairly certain he’ll have a great read. I appreciate you for sharing!

  11. IWIN说道:

    Hello! I simply wish to give you a huge thumbs up for your great info you’ve got right here on this post. I am coming back to your blog for more soon.

  12. YT MP3说道:

    I couldn’t resist commenting. Perfectly written!

  13. Tôm Đú说道:

    Greetings, I do think your website might be having internet browser compatibility issues. Whenever I look at your web site in Safari, it looks fine however when opening in I.E., it has some overlapping issues. I just wanted to give you a quick heads up! Aside from that, excellent website.

  14. blogmedia说道:

    Hello my loved one I want to say that this post is amazing great written and include almost all significant infos I would like to look extra posts like this

  15. I like reading through an article that will make men and women think. Also, thank you for allowing for me to comment.

  16. When I originally commented I seem to have clicked on the -Notify me when new comments are added- checkbox and now each time a comment is added I recieve 4 emails with the same comment. Perhaps there is an easy method you can remove me from that service? Thank you.

  17. Your style is unique compared to other people I have read stuff from. Many thanks for posting when you have the opportunity, Guess I will just book mark this web site.

  18. The very next time I read a blog, I hope that it won’t disappoint me as much as this one. I mean, Yes, it was my choice to read, however I truly thought you’d have something helpful to say. All I hear is a bunch of moaning about something that you could possibly fix if you were not too busy seeking attention.

  19. 78win说道:

    Your style is so unique compared to other people I have read stuff from. Thank you for posting when you have the opportunity, Guess I’ll just bookmark this site.

  20. 78win说道:

    I could not resist commenting. Well written.

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注