[c++] lambda递归

/ 76评论 / 1575阅读 / 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. sklep说道:

    Wow, incredible blog structure! How long have you ever been running a
    blog for? you make blogging look easy. The full look of
    your website is excellent, as well as the content material!
    You can see similar here najlepszy sklep

  2. tempmail说道:

    I appreciate your fortunate post. It was very funny, and it seems like you’ve reached a much nicer level now. How are we going to talk to one other now?

  3. tempmail说道:

    Hi, good post. Your website appears to have an issue with Internet Explorer. This problem will cause a lot of people to miss your good content because IE is still the most common browser.

  4. Temp Mail说道:

    I’ve been visiting this site for years, and it never fails to impress me with its fresh perspectives and wealth of knowledge. The attention to detail and commitment to quality is evident. This is a true asset for anyone seeking to learn and grow.

  5. Good day! Do you know if they make any plugins to help with Search Engine Optimization? I’m trying to
    get my blog to rank for some targeted keywords but I’m
    not seeing very good results. If you know of any please share.
    Many thanks! I saw similar art here: Link Building

  6. Howdy! Do you know if they make any plugins to help with Search Engine Optimization? I’m trying to get my blog to rank for some targeted keywords but
    I’m not seeing very good gains. If you know of any please share.
    Kudos! You can read similar blog here: Sklep internetowy

  7. Your blog is a treasure trove of wisdom and positivity I appreciate how you always seem to know just what your readers need to hear

  8. It means so much to receive positive feedback and know that my content is appreciated. I strive to bring new ideas and insights to my readers.

  9. It’s very interesting! If you need help, look here: ARA Agency

  10. alpilean reviews说道:

    I appreciate how well-researched and informative each post is It’s obvious how much effort you put into your work

  11. alpilean reviews说道:

    Your posts are so well-written and eloquent It’s impossible not to be moved by your words Keep using your voice to spread positivity

  12. e-commerce说道:

    Hi! Do you know if they make any plugins to help with SEO?
    I’m trying to get my blog to rank for some targeted keywords but I’m
    not seeing very good results. If you know of any please share.

    Thanks! You can read similar blog here: Sklep online

  13. What’s up, after reading this remarkable article i am as well happy to share
    my experience here with mates. I saw similar here: Sklep internetowy

  14. dobry sklep说道:

    Wow, incredible weblog structure! How long have you been blogging for?
    you make blogging glance easy. The total look of your site is fantastic, let alone the content material!
    You can see similar here najlepszy sklep

  15. Your posts always provide me with a new perspective and encourage me to look at things differently Thank you for broadening my horizons

  16. Your posts always provide me with a new perspective and encourage me to look at things differently Thank you for broadening my horizons

  17. alpilean reviews说道:

    Your writing is so eloquent and heartfelt It’s impossible not to be moved by your words Thank you for sharing your gift with the world

  18. puravive reviews说道:

    Let’s spread the love! Tag a friend who would appreciate this post as much as you did.

  19. You have a way of making each of your readers feel seen and heard That’s a special quality that not all bloggers possess Thank you for creating a safe space for us

  20. I appreciate how well-researched and informative each post is It’s obvious how much effort you put into your work

  21. I like the efforts you have put in this, regards for all the great content.

  22. temp mail说道:

    This is a nice blog as well. Your webpage loads quite quickly. Which hosting service are you using? I would like your affiliate link. My webpage should load just as rapidly.

  23. health massive说道:

    This is an amazing page. The outstanding information reveals the owner’s accountability. I’m in awe and eagerly await more amazing postings like this one.

  24. Wow superb blog layout How long have you been blogging for you make blogging look easy The overall look of your site is magnificent as well as the content

  25. Somebody essentially help to make significantly articles Id state This is the first time I frequented your web page and up to now I surprised with the research you made to make this actual post incredible Fantastic job

发表回复

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