[c++] lambda递归

/ 77评论 / 1679阅读 / 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. free email说道:

    I thought you did a great job on this. Although your language is excellent and the picture is enticing, you come across as nervous about what you might be giving next. If you save this walk, I hope you will come back here often.

  2. 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

  3. 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?

  4. 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.

  5. 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.

  6. 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

  7. 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

  8. 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

  9. 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.

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

  11. alpilean reviews说道:

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

  12. 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

  13. 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

  14. 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

  15. 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

  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. Your posts always provide me with a new perspective and encourage me to look at things differently Thank you for broadening my horizons

  18. 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

  19. puravive reviews说道:

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

  20. 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

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

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

  23. 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.

  24. 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.

  25. 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

  26. 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

回复 health massive 取消回复

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