目录
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: best online pharmacies in mexico – mexican online pharmacies prescription drugs
Thank you for the auspicious writeup It in fact was a amusement account it Look advanced to more added agreeable from you By the way how could we communicate
mexican border pharmacies shipping to usa: buying prescription drugs in mexico – mexico drug stores pharmacies
buying from online mexican pharmacy: mexican rx online – medication from mexico pharmacy
I wanted to take a moment to commend you on the outstanding quality of your blog. Your dedication to excellence is evident in every aspect of your writing. Truly impressive!
medication from mexico pharmacy best online pharmacies in mexico mexican mail order pharmacies
medication from mexico pharmacy: medication from mexico pharmacy – mexico drug stores pharmacies
mexico pharmacies prescription drugs: mexico drug stores pharmacies – mexico pharmacies prescription drugs
reputable mexican pharmacies online: pharmacies in mexico that ship to usa – buying prescription drugs in mexico
mexico drug stores pharmacies best online pharmacies in mexico mexico pharmacies prescription drugs
medicine in mexico pharmacies: reputable mexican pharmacies online – best online pharmacies in mexico
mexico pharmacies prescription drugs: purple pharmacy mexico price list – mexican online pharmacies prescription drugs
mexican mail order pharmacies: buying prescription drugs in mexico – mexico drug stores pharmacies
mexico pharmacy mexican pharmaceuticals online purple pharmacy mexico price list
п»їbest mexican online pharmacies: mexican online pharmacies prescription drugs – mexico drug stores pharmacies
pharmacies in mexico that ship to usa: medication from mexico pharmacy – mexican drugstore online
mexican rx online: reputable mexican pharmacies online – buying from online mexican pharmacy
mexico pharmacy buying from online mexican pharmacy purple pharmacy mexico price list
mexico drug stores pharmacies: medicine in mexico pharmacies – mexico pharmacies prescription drugs
mexico drug stores pharmacies: purple pharmacy mexico price list – best online pharmacies in mexico
buying prescription drugs in mexico online: best online pharmacies in mexico – pharmacies in mexico that ship to usa
best online pharmacies in mexico: reputable mexican pharmacies online – medication from mexico pharmacy
buying from online mexican pharmacy mexico pharmacy mexico drug stores pharmacies
mexico drug stores pharmacies: buying prescription drugs in mexico online – mexico drug stores pharmacies
mexican drugstore online mexican rx online buying prescription drugs in mexico online
reputable mexican pharmacies online: п»їbest mexican online pharmacies – mexican border pharmacies shipping to usa
purple pharmacy mexico price list: mexico drug stores pharmacies – medication from mexico pharmacy
mexico drug stores pharmacies: mexican border pharmacies shipping to usa – buying from online mexican pharmacy
mexico drug stores pharmacies: mexico drug stores pharmacies – mexican pharmaceuticals online
mexico pharmacy purple pharmacy mexico price list best online pharmacies in mexico
mexico drug stores pharmacies: mexican border pharmacies shipping to usa – mexico drug stores pharmacies
mexico drug stores pharmacies: best online pharmacies in mexico – mexican online pharmacies prescription drugs
Wow amazing blog layout How long have you been blogging for you made blogging look easy The overall look of your web site is magnificent as well as the content
mexico drug stores pharmacies mexican online pharmacies prescription drugs buying from online mexican pharmacy
http://mexicandeliverypharma.com/# mexican pharmaceuticals online
mexico drug stores pharmacies: mexican pharmaceuticals online – mexico drug stores pharmacies
mexican drugstore online: reputable mexican pharmacies online – pharmacies in mexico that ship to usa
mexican drugstore online: mexican rx online – mexican rx online
mexican online pharmacies prescription drugs: buying from online mexican pharmacy – mexico drug stores pharmacies
mexican border pharmacies shipping to usa mexico pharmacies prescription drugs mexican mail order pharmacies
https://mexicandeliverypharma.online/# п»їbest mexican online pharmacies
mexican online pharmacies prescription drugs: buying prescription drugs in mexico – best online pharmacies in mexico
medicine in mexico pharmacies: reputable mexican pharmacies online – mexico pharmacies prescription drugs
best online pharmacies in mexico best online pharmacies in mexico buying from online mexican pharmacy
reputable mexican pharmacies online: pharmacies in mexico that ship to usa – buying from online mexican pharmacy
medicine in mexico pharmacies: buying from online mexican pharmacy – mexican border pharmacies shipping to usa
medicine in mexico pharmacies: buying prescription drugs in mexico online – purple pharmacy mexico price list
mexican drugstore online: mexican drugstore online – mexican border pharmacies shipping to usa
pharmacies in mexico that ship to usa п»їbest mexican online pharmacies pharmacies in mexico that ship to usa
buying prescription drugs in mexico: mexican border pharmacies shipping to usa – buying prescription drugs in mexico online