目录
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;
}
farmacie online autorizzate elenco: Farmacie on line spedizione gratuita – top farmacia online
I really like looking through an article that will make people think. Also, thanks for allowing me to comment.
After going over a number of the blog articles on your blog, I seriously appreciate your way of blogging. I saved as a favorite it to my bookmark webpage list and will be checking back in the near future. Please visit my web site too and tell me how you feel.
I discovered your blog internet site on google and check a few of your early posts. Continue to keep up the extremely good operate. I just extra up your RSS feed to my MSN News Reader. Looking for forward to reading much more from you later on!…
Pretty! This has been a really wonderful article. Many thanks for providing this info.
Your positivity and optimism are contagious It’s evident that you genuinely care about your readers and their well-being
I really appreciate this post. I¡¦ve been looking everywhere for this! Thank goodness I found it on Bing. You’ve made my day! Thanks again
https://prednisonebestprice.pro/# order prednisone
zithromax over the counter uk: zithromax capsules – generic zithromax medicine
cost of propecia price: buying cheap propecia prices – order generic propecia without insurance
п»їcytotec pills online: buy cytotec over the counter – buy cytotec
tamoxifen alternatives premenopausal: tamoxifen lawsuit – who should take tamoxifen
Thank you for the auspicious writeup It in fact was a amusement account it Look advanced to far added agreeable from you However how can we communicate
where can you buy zithromax: buy zithromax no prescription – generic zithromax 500mg
I’m more than happy to uncover this page. I want to to thank you for ones time for this particularly fantastic read!! I definitely really liked every bit of it and I have you bookmarked to see new stuff in your website.
nolvadex estrogen blocker: tamoxifen rash pictures – common side effects of tamoxifen
Aw, this was an extremely nice post. Taking a few minutes and actual effort to create a top notch article… but what can I say… I put things off a lot and never seem to get anything done.
http://nolvadexbestprice.pro/# tamoxifen side effects forum
You’re so cool! I don’t think I’ve read through anything like this before. So wonderful to find someone with some original thoughts on this subject. Seriously.. thanks for starting this up. This web site is something that is needed on the web, someone with some originality.
http://prednisonebestprice.pro/# prednisone uk price
buy zithromax without presc: zithromax drug – zithromax 500 without prescription
order generic propecia without dr prescription: buy propecia pills – order cheap propecia
buy cheap prednisone: generic prednisone online – prednisone 30 mg
buy cytotec: buy misoprostol over the counter – buy cytotec in usa
https://nolvadexbestprice.pro/# benefits of tamoxifen
cytotec buy online usa: cytotec buy online usa – Misoprostol 200 mg buy online
tamoxifen generic: tamoxifen men – tamoxifen rash
prednisone 5 mg tablet price: prednisone cream rx – prednisone 10mg tablet price
I’m impressed, I have to admit. Rarely do I encounter a blog that’s equally educative and interesting, and without a doubt, you have hit the nail on the head. The problem is something that too few folks are speaking intelligently about. Now i’m very happy that I stumbled across this during my search for something concerning this.
does tamoxifen make you tired: tamoxifen lawsuit – tamoxifen dosage
cytotec pills buy online: п»їcytotec pills online – Abortion pills online
nolvadex pct: tamoxifen 20 mg – tamoxifen benefits
prednisone 40mg prednisone 60 mg price prednisone 2.5 mg daily
tamoxifen for gynecomastia reviews what is tamoxifen used for nolvadex gynecomastia
http://cytotecbestprice.pro/# buy cytotec over the counter
Use the Internet. Do whatever it takes to get the names, and then contact them.
https://cytotecbestprice.pro/# buy misoprostol over the counter
https://cytotecbestprice.pro/# Cytotec 200mcg price
tamoxifen for gynecomastia reviews: how does tamoxifen work – who should take tamoxifen
http://propeciabestprice.pro/# propecia order
buy zithromax without prescription online zithromax capsules price zithromax 500mg price in india
tamoxifen warning: femara vs tamoxifen – tamoxifen dosage
nolvadex gynecomastia nolvadex d nolvadex pills
http://prednisonebestprice.pro/# prednisone pill
http://zithromaxbestprice.pro/# zithromax coupon
https://cytotecbestprice.pro/# buy misoprostol over the counter
Cytotec 200mcg price: buy cytotec over the counter – buy cytotec over the counter
can you buy prednisone in canada prednisone 5 mg tablet cost can i buy prednisone online without prescription
https://prednisonebestprice.pro/# prednisone 40 mg price
where can i purchase zithromax online: zithromax online usa – where can i buy zithromax capsules