[c++] lambda递归

/ 4,480评论 / 13003阅读 / 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. Brandenven说道:

    buy prednisone online no script: raypharm – prednisone tabs 20 mg

  2. StevenWearo说道:

    get cheap clomid without insurance: cheap clomid – order cheap clomid without prescription

  3. porn说道:

    You should be a part of a contest for one of the best sites on the net. I’m going to highly recommend this blog!

  4. Derekjup说道:

    dapoxetine online: buy dapoxetine online – priligy max pharm

  5. Brandenven说道:

    buy generic clomid without dr prescription: clomid purchase online rex pharm – get cheap clomid no prescription

  6. Derekjup说道:

    buy prednisone canadian pharmacy: prednisoneraypharm – prednisone uk price

  7. Brandenven说道:

    dapoxetine price: Priligy tablets – max pharm

  8. The next time I read a blog, Hopefully it does not fail me just as much as this one. After all, I know it was my choice to read, however I truly thought you would have something interesting to talk about. All I hear is a bunch of whining about something that you can fix if you were not too busy seeking attention.

  9. I blog often and I genuinely thank you for your content. Your article has truly peaked my interest. I am going to book mark your website and keep checking for new information about once a week. I subscribed to your Feed too.

  10. StevenWearo说道:

    buy dapoxetine online: priligy max pharm – buy priligy max pharm

  11. This article is fantastic! Full of valuable information and extremely well-written. Thank you for offering this.

  12. Brandenven说道:

    cost generic clomid: cheap clomid – cost clomid tablets

  13. StevenWearo说道:

    5 mg prednisone tablets: raypharm – buy prednisone without a prescription best price

  14. Derekjup说道:

    can i purchase generic clomid online: generic clomid – order cheap clomid without rx

  15. Derekjup说道:

    priligy max pharm: priligy – dapoxetine price

  16. Узнай все о на что влияет варикоцеле варикоцеле

  17. Узнай все о степени варикоцеле варикоцеле

  18. Brandenven说道:

    priligy max pharm: cheap priligy – priligy

  19. ALPHA BITES说道:

    Excellent post. It’s extremely clear and filled with valuable details. Many thanks for sharing this content.

  20. Bradleyarrip说道:

    where to buy generic clomid without prescription get cheap clomid pills get clomid online

  21. read here说道:

    Can I simply say what a relief to discover somebody that truly understands what they’re discussing on the net. You definitely realize how to bring a problem to light and make it important. More and more people ought to look at this and understand this side of the story. I can’t believe you’re not more popular given that you certainly have the gift.

  22. Brandenven说道:

    cost of generic clomid without insurance: cheap clomid – cheap clomid now

  23. Adored the information shared in this post. It’s very well-written and packed with valuable insight. Great work!

发表回复

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