目录
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;
}
I absolutely love your website.. Pleasant colors & theme. Did you make this amazing site yourself? Please reply back as I’m trying to create my own personal website and would love to find out where you got this from or just what the theme is called. Appreciate it!
Профессиональный сервисный центр по ремонту бытовой техники с выездом на дом.
Мы предлагаем: ремонт крупногабаритной техники в челябинске
Наши мастера оперативно устранят неисправности вашего устройства в сервисе или с выездом на дом!
Профессиональный сервисный центр по ремонту бытовой техники с выездом на дом.
Мы предлагаем: сервисные центры по ремонту техники в барнауле
Наши мастера оперативно устранят неисправности вашего устройства в сервисе или с выездом на дом!
Marine News. World Ship Society.
order Rybelsus for weight loss Rybelsus 14 mg price cheap Rybelsus 14 mg
ivermectin price uk: stromectol best price – buy minocycline online
https://stromectol.agency/# ivermectin lotion cost
generic zithromax online paypal
Профессиональный сервисный центр ремонт экрана телефона ремонт телефонов москва дешево
Профессиональный сервисный центр по ремонту сотовых телефонов в Москве.
Мы предлагаем: ремонт телефонов по близости
Наши мастера оперативно устранят неисправности вашего устройства в сервисе или с выездом на дом!
cost of neurontin 100mg buy gabapentin neurontin 200 mg capsules
Тут делают продвижение seo медицина стратегия с роботами
Профессиональный сервисный центр по ремонту автомагнитол в Москве.
Мы предлагаем: починить магнитолу
Наши мастера оперативно устранят неисправности вашего устройства в сервисе или с выездом на дом!
http://semaglutide.win/# rybelsus cost
sugar defender reviews: https://sugardefenderreviews.pages.dev
Профессиональный сервисный центр по ремонту автомагнитол в Москве.
Мы предлагаем: ремонт автомагнитол в москве
Наши мастера оперативно устранят неисправности вашего устройства в сервисе или с выездом на дом!
https://amoxil.llc/# order amoxicillin online
Тут делают продвижение разработка сайтов медицинских организаций seo для медицинского центра
https://amoxil.llc/# can we buy amoxcillin 500mg on ebay without prescription
zithromax 500mg
магазин сейфов предлагает сейф 3 класса сейф 3 класс взломостойкости
магазин сейфов предлагает сейф 3 класс взломостойкости купить сейф 3 класса
buy amoxicillin online uk: amoxil best price – medicine amoxicillin 500mg
http://zithromax.company/# zithromax buy online no prescription
https://semaglutide.win/# Buy compounded semaglutide online
where can i get zithromax
магазин сейфов предлагает взломостойкие сейфы 3 класса купить сейф 3 класса
Chandragupta II assumed the title of “Vikramaditya”, in celebration of his victory over the Western Satraps.
Another option is to make use of colour to unite objects that haven’t any common thread.
The bus continues to Lagos, or you can have a espresso and proceed to Tunes & Lagos by prepare.
Single of the Week: The Disciple’s ‘Bottom of Society’ Takes the Rap Scene by Storm.
https://amoxil.llc/# amoxicillin no prescription
A series of attacks started on 11 July 2009 and continued for more than 5 days.
zithromax 1000 mg online zithromax for sale zithromax over the counter
Please enhance this section by adding secondary or tertiary sources.
I shot multi-gun with a semi and I’m positive with self-loaders.
zithromax generic price order zithromax where can i get zithromax
http://amoxil.llc/# buy amoxicillin 500mg uk
zithromax 250 price
topical ivermectin cost: stromectol for sale – ivermectin buy australia
https://stromectol.agency/# buy minocycline 50mg online
can i buy zithromax online
generic amoxicillin cost amoxil best price amoxicillin 875 mg tablet
магазин сейфов предлагает взломостойкие сейфы 3 класса сейфы 3 класса
cost of neurontin 600mg gabapentin price buy gabapentin
https://zithromax.company/# zithromax 250
where to get zithromax
https://zithromax.company/# zithromax 500
Buy compounded semaglutide online: Rybelsus 14 mg price – buy semaglutide online
semaglutide rybelsus Rybelsus 14 mg price
https://zithromax.company/# buy zithromax 1000 mg online
how to buy zithromax online
http://semaglutide.win/# order Rybelsus for weight loss
http://semaglutide.win/# Buy compounded semaglutide online
Buy semaglutide pills rybelsus cost Rybelsus 7mg
https://zithromax.company/# generic zithromax 500mg india
This site was… how do I say it? Relevant!! Finally I have found something that helped me. Many thanks!