目录
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;
}
buying prescription drugs in mexico online medication from mexico pharmacy mexican border pharmacies shipping to usa
I’d like to thank you for the efforts you have put in penning this site. I really hope to see the same high-grade blog posts from you later on as well. In truth, your creative writing abilities has motivated me to get my own site now 😉
http://mexicanpharm24.pro/# buying from online mexican pharmacy
top 10 pharmacies in india
buy prescription drugs from canada http://indianpharmdelivery.com/# india pharmacy
Профессиональный сервисный центр по ремонту бытовой техники с выездом на дом.
Мы предлагаем: сервисные центры в барнауле
Наши мастера оперативно устранят неисправности вашего устройства в сервисе или с выездом на дом!
indian pharmacy paypal buy prescription drugs from india online shopping pharmacy india
men ed https://mexicanpharm24.pro/# mexican rx online
Профессиональный сервисный центр по ремонту бытовой техники с выездом на дом.
Мы предлагаем: сервисные центры в челябинске
Наши мастера оперативно устранят неисправности вашего устройства в сервисе или с выездом на дом!
Профессиональный сервисный центр по ремонту бытовой техники с выездом на дом.
Мы предлагаем: ремонт бытовой техники в барнауле
Наши мастера оперативно устранят неисправности вашего устройства в сервисе или с выездом на дом!
http://mexicanpharm24.pro/# buying prescription drugs in mexico
top 10 online pharmacy in india
cheapest online pharmacy india indian pharmacy cheapest online pharmacy india
Профессиональный сервисный центр по ремонту бытовой техники с выездом на дом.
Мы предлагаем: сервисные центры в челябинске
Наши мастера оперативно устранят неисправности вашего устройства в сервисе или с выездом на дом!
Профессиональный сервисный центр по ремонту сотовых телефонов в Москве.
Мы предлагаем: ноутбук ремонт
Наши мастера оперативно устранят неисправности вашего устройства в сервисе или с выездом на дом!
buy prescription drugs http://drugs24.pro/# cat antibiotics without pet prescription
Truly liked reading this entry. It’s very well-written and full of valuable information. Thanks for sharing this.
buy prescription drugs from india п»їlegitimate online pharmacies india п»їlegitimate online pharmacies india
Профессиональный сервисный центр ремонт кнопочных телефонов ремонт телефонов ближайший ко мне
Профессиональный сервисный центр по ремонту бытовой техники с выездом на дом.
Мы предлагаем: ремонт крупногабаритной техники в барнауле
Наши мастера оперативно устранят неисправности вашего устройства в сервисе или с выездом на дом!
https://mexicanpharm24.pro/# purple pharmacy mexico price list
mail order pharmacy india
I was so impressed with all the many decorations you place time and effort into.
Additionally they were asked to register individuals into the Venezuelan government homeland card, to safe medical companies, and refuse treatment to those who didn’t apply for it.
In 1800 the Northwest Territory was cut in two and Wisconsin grew to become part of the western division, referred to as Indiana Territory.
It did not take long for Jon Eiden to make history in the 2019 “Lake Winnebago System” sturgeon spearing season.
But less complicated delights can be discovered at places like Hemisfair, an urban park on the location of the 1968 World’s Truthful that features an inclusive playground, splash pad, games plaza, and other areas designed for play and gathering.
She is survived by three daughters, Marilyn Vose of California, Pamela Walker of Nottingham and Cynthia Busch of Winterport; two sons, L. Philip Cotton Jr.
And there’s quite a bit – lots of cultural work to do in Italy in case you really want to enhance the scenario which, in these summer time days, seems it’s getting worse as a result of the many episodes of racism skilled by black Italians and Africans living in Italy.
Way cool! Some extremely valid points! I appreciate you penning this post and the rest of the site is also very good.
Hi! I just would like to give you a big thumbs up for your great info you have got right here on this post. I am coming back to your web site for more soon.
The second-largest referendum asked for $900,000 for site enhancements at Holmen Highschool.
Профессиональный сервисный центр по ремонту бытовой техники с выездом на дом.
Мы предлагаем: сервис центры бытовой техники челябинск
Наши мастера оперативно устранят неисправности вашего устройства в сервисе или с выездом на дом!
best ed pill treatment with drugs canadian online pharmacy
Hello there! This post couldn’t be written any better! Looking at this article reminds me of my previous roommate! He constantly kept preaching about this. I am going to forward this article to him. Fairly certain he’s going to have a very good read. I appreciate you for sharing!
https://drugs24.pro/# medication for ed
buy prescription drugs from india