目录
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;
}
cheap Rybelsus 14 mg: cheap Rybelsus 14 mg – rybelsus
ivermectin online cheapest stromectol minocycline weight gain
https://zithromax.company/# order zithromax over the counter
zithromax without prescription
https://gabapentin.auction/# neurontin tablets no script
https://amoxil.llc/# cheap amoxicillin 500mg
neurontin 100mg cap gabapentin best price ordering neurontin online
Профессиональный сервисный центр по ремонту моноблоков iMac в Москве.
Мы предлагаем: ремонт imac в москве
Наши мастера оперативно устранят неисправности вашего устройства в сервисе или с выездом на дом!
http://zithromax.company/# how to get zithromax online
where can i purchase zithromax online
https://gabapentin.auction/# neurontin generic
https://zithromax.company/# zithromax 250 mg
generic zithromax 500mg zithromax best price buy cheap zithromax online
amoxicillin 500mg prescription: amoxicillin 50 mg tablets – amoxicillin 500 mg capsule
https://semaglutide.win/# buy semaglutide online
https://zithromax.company/# zithromax 500mg
where can i buy zithromax in canada
Профессиональный сервисный центр по ремонту моноблоков iMac в Москве.
Мы предлагаем: мастер по ремонту imac
Наши мастера оперативно устранят неисправности вашего устройства в сервисе или с выездом на дом!
Hey there You have done a fantastic job I will certainly digg it and personally recommend to my friends Im confident theyll be benefited from this site
rybelsus Buy semaglutide pills Semaglutide pharmacy price
https://gabapentin.auction/# neurontin 800 mg pill
http://semaglutide.win/# buy rybelsus
Simply desire to say your article is as surprising The clearness in your post is simply excellent and i could assume you are an expert on this subject Fine with your permission let me to grab your feed to keep up to date with forthcoming post Thanks a million and please carry on the gratifying work
https://gabapentin.auction/# buy neurontin online
buy rybelsus Rybelsus 14 mg cheap Rybelsus 14 mg
how to buy amoxicillin online: buy amoxil – antibiotic amoxicillin
http://stromectol.agency/# stromectol cream
zithromax price south africa
http://amoxil.llc/# amoxicillin 800 mg price
Профессиональный сервисный центр по ремонту моноблоков iMac в Москве.
Мы предлагаем: сервисный центр imac
Наши мастера оперативно устранят неисправности вашего устройства в сервисе или с выездом на дом!
rybelsus generic rybelsus order Rybelsus for weight loss
https://semaglutide.win/# cheap Rybelsus 14 mg
Тут делают продвижение seo-продвижение медицинских сайтов продвижение в поисковых системах медицинского сайта
amoxicillin 500mg capsule buy online: cheapest amoxil – can i buy amoxicillin online
https://gabapentin.auction/# neurontin gabapentin
zithromax prescription zithromax best price can i buy zithromax online
http://semaglutide.win/# Rybelsus 14 mg price
Hi Neat post There is a problem along with your website in internet explorer would test this IE still is the market chief and a good section of other folks will pass over your magnificent writing due to this problem
https://amoxil.llc/# purchase amoxicillin online
zithromax without prescription
neurontin medication: cheapest gabapentin – how much is neurontin pills
This is a topic which is close to my heart… Best wishes! Exactly where are your contact details though?
https://stromectol.agency/# minocycline capsule
An outstanding share! I’ve just forwarded this onto a coworker who has been doing a little research on this. And he actually ordered me dinner due to the fact that I stumbled upon it for him… lol. So let me reword this…. Thank YOU for the meal!! But yeah, thanx for spending some time to talk about this issue here on your web site.
where to buy amoxicillin 500mg can you purchase amoxicillin online antibiotic amoxicillin
https://amoxil.llc/# amoxicillin 500mg capsule buy online
ivermectin australia: stromectol best price – minocycline 100mg for sale
I’m extremely pleased to find this site. I want to to thank you for ones time for this particularly wonderful read!! I definitely liked every part of it and i also have you bookmarked to see new things on your blog.
https://semaglutide.win/# Buy semaglutide pills
Adored the insight in this post. It’s highly detailed and filled with beneficial information. Great job!
https://semaglutide.win/# Semaglutide pharmacy price
zithromax 250 mg tablet price
buy rybelsus Rybelsus 14 mg price order Rybelsus for weight loss
http://semaglutide.win/# Rybelsus 7mg
https://gabapentin.auction/# prescription price for neurontin
zithromax cost
rybelsus generic: Buy compounded semaglutide online – semaglutide