目录
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;
}
Начните массовую индексацию ссылок в Google прямо cейчас!
Быстрая индексация ссылок имеет ключевое значение для успеха вашего онлайн-бизнеса. Чем быстрее поисковые системы обнаружат и проиндексируют ваши ссылки, тем быстрее вы сможете привлечь новую аудиторию и повысить позиции вашего сайта в результатах поиска.
Не теряйте времени! Начните пользоваться нашим сервисом для ускоренной индексации внешних ссылок в Google и Yandex. Зарегистрируйтесь сегодня и получите первые результаты уже завтра. Ваш успех в ваших руках!
The passive fireplace proofing programs market measurement from the commercial section is predicted to observe over 4.5 CAGR by 2032.
It was observed that Schumacher was very sensitive and flexible on the gasoline and brakes.
CNN also reported that Trump and Vice President Mike Pence called Kemp on Tuesday night time to precise support for Kemp’s choice.
Canon’s emblem has modified a couple of times since the company began, but the present one has been in use since 1956.
best erectile dysfunction pills natural help for ed canadian drug prices
Wonderful article! We will be linking to this great content on our website. Keep up the great writing.
You’ve articulated this issue perfectly.오피
As retaliation for Warwick being in his means, Schumacher swerved his Sauber into Warwick’s car, hitting the Jaguar’s nose and front wheel.
But most are pieces of junk.
Safer at House”-style order after state one was struck down”.
A composite sandwich cabinet sometimes offers more than twice the thermal insulation of a steel shelter with the same insulation thickness.
Despite not getting all of the solutions he needed after he and K.O.
http://drugs24.pro/# cheap medications online
india pharmacy
mexican drugstore online: medication from mexico pharmacy – mexican pharmaceuticals online
Eiden’s fish went an astonishing 85.5 inches from snout to tail.
This site was… how do you say it? Relevant!! Finally I’ve found something that helped me. Kudos!
treat ed ed trial pack natural drugs for ed
discount prescription drugs: ed meds online without doctor prescription – best medicine for ed
http://drugs24.pro/# ed drugs compared
indian pharmacies safe
drugs online: male enhancement pills – best online canadian pharmacy
When I initially commented I seem to have clicked the -Notify me when new comments are added- checkbox and from now on whenever a comment is added I get four emails with the exact same comment. Is there an easy method you can remove me from that service? Thanks a lot.
world pharmacy india online shopping pharmacy india online shopping pharmacy india
Профессиональный сервисный центр по ремонту сотовых телефонов в Москве.
Мы предлагаем: мастерская по ремонту сотовых телефонов
Наши мастера оперативно устранят неисправности вашего устройства в сервисе или с выездом на дом!
reputable mexican pharmacies online п»їbest mexican online pharmacies mexico drug stores pharmacies
Nitric boost ultra reviews : https://nitricboostultrareviews.usaloves.com
Nitric boost ultra reviews : https://nitricboostultrareviews.usaloves.com
Nitric boost ultra reviews : https://nitricboostultrareviews.usaloves.com
mexican border pharmacies shipping to usa: buying prescription drugs in mexico – pharmacies in mexico that ship to usa
Профессиональный сервисный центр мастер по ремонту телефонов где можно отремонтировать телефон
canadian online drugs https://drugs24.pro/# best male enhancement pills
Профессиональный сервисный центр по ремонту сотовых телефонов в Москве.
Мы предлагаем: ремонт андроид телефонов
Наши мастера оперативно устранят неисправности вашего устройства в сервисе или с выездом на дом!
http://indianpharmdelivery.com/# pharmacy website india
п»їlegitimate online pharmacies india
india online pharmacy: cheapest online pharmacy india – indian pharmacy online
Профессиональный сервисный центр сдача телефона в ремонт сервисный центр смартфонов
canadian drug pharmacy http://mexicanpharm24.pro/# pharmacies in mexico that ship to usa
medication from mexico pharmacy: pharmacies in mexico that ship to usa – reputable mexican pharmacies online
Профессиональный сервисный центр по ремонту сотовых телефонов в Москве.
Мы предлагаем: где отремонтировать телефон
Наши мастера оперативно устранят неисправности вашего устройства в сервисе или с выездом на дом!
reputable mexican pharmacies online buying prescription drugs in mexico mexico drug stores pharmacies
Профессиональный сервисный центр сервис ремонт телефонов ремонт смартфонов
https://indianpharmdelivery.com/# cheapest online pharmacy india
best online pharmacy india
buying prescription drugs in mexico purple pharmacy mexico price list mexican drugstore online
india pharmacy mail order: reputable indian pharmacies – online pharmacy india
best online pharmacy india: top 10 online pharmacy in india – online pharmacy india
drugs online https://indianpharmdelivery.com/# Online medicine home delivery
systemen io: https://systemee.systeme.io
reputable indian pharmacies india pharmacy mail order indian pharmacies safe
mail order pharmacy india: п»їlegitimate online pharmacies india – indian pharmacy
https://indianpharmdelivery.com/# Online medicine order
reputable indian pharmacies
systeme io: https://systemee.systeme.io