前言
很多时候,我们需要定义一些小的函数
比如在sort()
时指定比较函数cmp()
:
sort(a+1, a+1+n, cmp) bool cmp(const int a, cnost int b) {return a > b;}
但这么小的函数写在外面会有一点不优雅
于是我们可以用 λ表达式 来解决这个问题
解决方案
Lambda表达式如果叫做匿名函数的话可能更能凸显他的特性
详细情况请参阅参考资料中的链接
对于竞赛来讲,似乎Lambda表达式这么用就好:
static auto cmp = [](int a, int b) {return a > b;}; sort(a+1, a+1+n, cmp);
或者再做绝一点:
sort(a+1, a+1+n, [](int a, int b) {return a > b;});
是不是感觉很强 ( •̀ ω •́ )y
兼容性
无论是 Lambda表达式 或是auto
都是 C++ 11里的东西
直接交到不支持 C++ 11 的OJ上会CE
于是我们需要加上下面这句指令,以使编译器忽略该错误:
#pragma GCC diagnostic error "-std=c++11"
当然gcc的版本需要在4.7以上,否则编译器根本不知道Lambda表达式是什么 QwQ
Quality content is the main to attract the users to go to see the web
page, that’s what this website is providing.
Please let me know if you’re looking for a article writer
for your weblog. You have some really good articles and I
believe I would be a good asset. If you ever want to
take some of the load off, I’d love to write some articles for your blog in exchange for a link back to mine.
Please send me an email if interested. Thank you!
This web site certainly has all of the information I needed concerning this
subject and didn’t know who to ask.
I think this is among the most important info for me. And i’m glad
reading your article. However wanna observation on some basic issues, The site style is perfect, the articles is truly nice : D.
Excellent job, cheers
Way cool! Some extremely valid points! I appreciate you penning this article and also
the rest of the website is also really good.
Someone essentially assist to make critically articles I might
state. That is the first time I frequented your web page and so far?
I surprised with the research you made to create
this particular publish extraordinary. Fantastic activity!
It is actually a great and useful piece of information. I am satisfied that you just shared this useful
information with us. Please keep us up to date like this.
Thank you for sharing.
Fastidious answer back in return of this matter with real arguments and telling the whole thing on the
topic of that.
I don’t even know how I ended up here, but I thought this
post was good. I do not know who you are but definitely
you are going to a famous blogger if you are not already 😉 Cheers!
Woah! I’m really loving the template/theme of this blog.
It’s simple, yet effective. A lot of times it’s very difficult to get that
“perfect balance” between user friendliness and visual appeal.
I must say that you’ve done a superb job with this.
Also, the blog loads super quick for me on Internet explorer.
Superb Blog!
I’m not sure exactly why but this blog is loading extremely slow for me. Is anyone else having this problem or is it a problem on my end? I’ll check back later and see if the problem still exists.
Valuable information. Fortunate me I found your website
by accident, and I’m shocked why this twist of
fate did not took place earlier! I bookmarked it.
You ought to take part in a contest for one of the finest sites on the net.
I am going to highly recommend this web site!
Thanks for some other magnificent post. Where else could anyone
get that type of info in such an ideal manner of writing?
I’ve a presentation subsequent week, and I’m at the look for such
information.
Wonderful site. Plenty of useful info here. I’m sending it to
some pals ans additionally sharing in delicious. And obviously, thank you on your sweat!
Yesterday, while I was at work, my sister stole my iPad and tested to see if it can survive a 40 foot drop,
just so she can be a youtube sensation. My apple ipad is now destroyed
and she has 83 views. I know this is completely off topic but I had to share
it with someone!
What’s up to every body, it’s my first visit of
this webpage; this web site contains awesome and truly good information for readers.
Hey There. I discovered your blog the use of msn. This is a really well written article.
I’ll be sure to bookmark it and return to learn extra of
your helpful information. Thanks for the post.
I will definitely comeback.
of course like your web-site but you need to check the spelling on several
of your posts. Several of them are rife with spelling
problems and I find it very troublesome to inform the reality on the other hand I’ll certainly come back
again.
This is a topic that’s near to my heart… Cheers! Where are your contact details though?
Hey There. I found your blog using msn. This is an extremely
well written article. I will be sure to bookmark it and return to read more of your useful info.
Thanks for the post. I will certainly comeback.
I truly appreciate this post. I have been looking everywhere for this! Thank goodness I found it on Bing. You have made my day! Thank you again