目录
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;
}
Тут можно преобрести оружейный сейф на заказ москва оружейный сейф на заказ москва
Тут можно преобрести сейф оружейный купить москва оружейные шкафы в москве
erectial disfunction Best Canadian online pharmacy pharmacy medications
pharmacies in mexico that ship to usa Mexican Pharm Gate mexico pharmacies prescription drugs
cheapest online pharmacy india: Best online Indian pharmacy – india pharmacy
Тут можно преобрести сейф противопожарный сейф москва огнестойкий купить
Тут можно преобрести сейфы пожаростойкие купить сейф огнестойкий
Тут можно преобрести оружейные сейфы цена оружейный сейф купить
Тут можно преобрести сейф для ружья цена сейф шкаф купить
Excellent article. I found the details highly beneficial. Adored the method you clarified the content.
mexican border pharmacies shipping to usa: mexicanpharmgate.com – mexican drugstore online
http://canadiandrugsgate.com/# cheap ed pills
http://canadiandrugsgate.com/# erectile dysfunction treatments
Greetings! Very useful advice in this particular post! It is the little changes that will make the largest changes. Thanks a lot for sharing!
mexico drug stores pharmacies mexican pharmacy mexican pharmaceuticals online
vacuum pumps for ed: canadiandrugsgate.com – erectional dysfunction
Здесь можно преобрести модели сейфов сейфы москва
Здесь можно преобрести купить сейф оптом сейф цена купить
Excellent article. I’m experiencing some of these issues as well..
indian pharmacies safe: indianpharmacyeasy – п»їlegitimate online pharmacies india
Oh my goodness! Incredible article dude! Thank you, However I am experiencing troubles with your RSS. I don’t understand the reason why I can’t join it. Is there anyone else getting the same RSS issues? Anyone that knows the answer can you kindly respond? Thanx!
The very next time I read a blog, I hope that it does not disappoint me just as much as this particular one. I mean, I know it was my choice to read through, nonetheless I truly thought you would probably have something interesting to say. All I hear is a bunch of moaning about something you could fix if you weren’t too busy seeking attention.
Здесь можно преобрести купить сейф сейф цена
mexican mail order pharmacies: mexicanpharmgate.com – mexican pharmaceuticals online
Здесь можно преобрести купить сейф в москве цена сейф купить
do i have ed canadian pharmacy drugs gate drug pharmacy
I enjoy reading an article that will make men and women think. Also, thanks for allowing me to comment.
Oh my goodness! Incredible article dude! Thank you, However I am encountering difficulties with your RSS. I don’t know why I can’t subscribe to it. Is there anybody else having similar RSS issues? Anyone that knows the solution will you kindly respond? Thanx!!
http://mexicanpharmgate.com/# mexico pharmacies prescription drugs
best drug for ed: Canadian pharmacy best prices – ed medication online
https://indianpharmacyeasy.com/# online shopping pharmacy india
Тут можно преобрести сейф охотничий купить оружейные шкафы
Тут можно преобрести оружейный сейф на заказ москва купить оружейный сейф
mexican pharmaceuticals online: MexicanPharmGate – buying prescription drugs in mexico online
Wonderful post! We are linking to this great content on our site. Keep up the good writing.
An interesting discussion is worth comment. I do believe that you need to publish more on this subject matter, it might not be a taboo matter but usually people don’t discuss such subjects. To the next! Many thanks!
Тут можно преобрести купить сейф огнестойкий в москве сейф жаростойкий
Тут можно преобрести сейф для оружия купить в москве купить сейф под ружье
Тут можно преобрести огнеупорные сейфы купить сейф огнестойкий
http://canadiandrugsgate.com/# cheap erectile dysfunction pill
indian pharmacy: Indian pharmacy to USA – Online medicine order
ed cures that actually work canadiandrugsgate dysfunction erectile
Тут можно преобрести сейф жаростойкий купить огнестойкий сейф в москве
Тут можно преобрести пожаростойкие сейфы сейф несгораемый купить
This web site truly has all of the information I wanted about this subject and didn’t know who to ask.
https://mexicanpharmgate.com/# mexican mail order pharmacies
Online medicine home delivery: Best Indian pharmacy – online pharmacy india
sugar defender ingredients As somebody that’s always been cautious about my blood glucose, discovering Sugar Defender
has actually been an alleviation. I feel a lot more in control, and my recent examinations
have revealed positive enhancements. Knowing I have a dependable supplement
to support my routine gives me peace of mind.
I’m so happy for Sugar Protector’s effect on my health!
mexican online pharmacies prescription drugs mexican pharmacy buying prescription drugs in mexico online
buy online pharmacy: Canadian pharmacy online – ed drugs compared