目录
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递归
- 对于 lambda 实现递归,由于它是匿名函数,本身没有函数名,我们是把他赋值给了一个变量。
- 但要注意的是,像下面这样直接调用是不行的:
- 因为在 声明lambda表达式时,变量fun应当视为还没声明,fun需要等lambda表达式构造完成后赋值过来才算完成声明,因此在 lambda 内是不能访问 fun 这个变量的。
int main() {
auto fun = [&fun](int value) {
if(value < 0) {
return;
}
cout << value << endl;
// 这里是不行的!!!
fun(value - 1);
};
fun(10);
return 0;
}
- 既然如此,我们可以在lambda表达式前先声明一个 “容器”,让它去保存lambda,并且在声明 lambda时,由于这个容器是之前声明好的,因此可以引用捕获它,然后在 lambda内取到自己调用即可:
#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;
}
http://edpillpharmacy.store/# edmeds
Some fans go all out, though, painting themselves from head to toe in their team’s colors and spelling words with the letters on their bare chests, even on frigid winter nights.
Most popular Monte of the year was the “S,” which now served as the base model.
indian pharmacies safe: Online India pharmacy – top 10 pharmacies in india
indianpharmacy com: Top mail order pharmacies – buy prescription drugs from india
After I initially left a comment I appear to have clicked on the -Notify me when new comments are added- checkbox and from now on whenever a comment is added I recieve 4 emails with the same comment. Is there an easy method you can remove me from that service? Cheers.
I blog often and I seriously thank you for your information. The article has really peaked my interest. I will take a note of your site and keep checking for new information about once a week. I subscribed to your RSS feed too.
When I originally left a comment I appear to have clicked the -Notify me when new comments are added- checkbox and from now on every time a comment is added I get four emails with the exact same comment. There has to be an easy method you are able to remove me from that service? Kudos.
purple pharmacy mexico price list: Best online Mexican pharmacy – pharmacies in mexico that ship to usa
online ed medication: Best ED pills non prescription – ed meds cheap
Oh my goodness! Amazing article dude! Thank you, However I am having issues with your RSS. I don’t know the reason why I can’t join it. Is there anyone else having identical RSS problems? Anyone that knows the solution can you kindly respond? Thanx.
http://mexicopharmacy.win/# medicine in mexico pharmacies
http://indiapharmacy.shop/# mail order pharmacy india
Hi there! I just want to offer you a huge thumbs up for your excellent info you have got here on this post. I’ll be returning to your site for more soon.
What i do not realize is in fact how you are no longer actually much more wellfavored than you might be right now Youre very intelligent You recognize thus considerably in relation to this topic made me in my view believe it from numerous numerous angles Its like men and women are not fascinated until it is one thing to do with Lady gaga Your own stuffs excellent All the time handle it up
I was more than happy to find this site. I need to to thank you for your time just for this fantastic read!! I definitely liked every part of it and i also have you book-marked to see new information on your site.
Appreciated the information in this entry. It’s highly detailed and filled with beneficial details. Fantastic effort!
Genuinely appreciated this post. It provided tons of helpful information. Fantastic job on composing this.
mail order pharmacy india: Online medicine home delivery – online pharmacy india
https://edpillpharmacy.store/# cheap ed treatment
online ed treatments
mexican mail order pharmacies: Mexico pharmacy online – mexico drug stores pharmacies
That is a very good tip particularly to those fresh to the blogosphere. Brief but very precise info… Thank you for sharing this one. A must read article!
https://indiapharmacy.shop/# top 10 online pharmacy in india
online erectile dysfunction pills
Really enjoyed going through this entry. It’s highly clear and full of valuable insight. Many thanks for offering this.
Adored the details in this article. It’s very well-researched and filled with beneficial details. Great effort!
http://indiapharmacy.shop/# п»їlegitimate online pharmacies india
https://edpillpharmacy.store/# buy erectile dysfunction pills
https://edpillpharmacy.store/# discount ed pills
discount ed meds
https://mexicopharmacy.win/# mexican drugstore online
ed medications online
http://mexicopharmacy.win/# mexican online pharmacies prescription drugs
order ed pills
cheapest online ed treatment: Best ED meds online – cheap ed drugs
online erectile dysfunction pills: Best ED meds online – cheapest ed pills
https://mexicopharmacy.win/# mexico drug stores pharmacies
cheapest ed meds
http://indiapharmacy.shop/# top 10 online pharmacy in india
https://edpillpharmacy.store/# edmeds
Hello there! This article couldn’t be written any better! Going through this article reminds me of my previous roommate! He constantly kept preaching about this. I’ll send this article to him. Pretty sure he will have a good read. Many thanks for sharing!
https://tadalafil.auction/# cialis with daxopretine
http://tadalafil.auction/# where can i buy cialis online in canada
viagra vs cialis: Cheap Viagra 100mg – real viagra without a doctor prescription
buy generic viagra online: Buy Viagra online in USA – viagra cost
May I just say what a comfort to uncover someone that genuinely understands what they’re talking about on the internet. You certainly understand how to bring an issue to light and make it important. A lot more people should look at this and understand this side of your story. I was surprised you’re not more popular because you most certainly have the gift.
cialis with dapoxitine: cialis viagra levitra young yahoo – cialis overnight shipping
Normally I do not read article on blogs however I would like to say that this writeup very forced me to try and do so Your writing style has been amazed me Thanks quite great post
generic viagra without a doctor prescription: Viagra without a doctor prescription – viagra coupons
Howdy! I just would like to offer you a big thumbs up for the excellent info you have right here on this post. I will be coming back to your web site for more soon.
I loved as much as youll receive carried out right here The sketch is tasteful your authored material stylish nonetheless you command get bought an nervousness over that you wish be delivering the following unwell unquestionably come more formerly again since exactly the same nearly a lot often inside case you shield this hike
http://sildenafil.llc/# viagra without prescription
https://sildenafil.llc/# viagra professional
Good information. Lucky me I came across your website by chance (stumbleupon). I’ve saved it for later!
Excellent web site you’ve got here.. It’s difficult to find excellent writing like yours nowadays. I honestly appreciate people like you! Take care!!