Skip to Content
Effective Modern C++(中文版)
book

Effective Modern C++(中文版)

by Scott Meyers
April 2018
Intermediate to advanced
303 pages
4h 54m
Chinese
China Electric Power Press Ltd.
Content preview from Effective Modern C++(中文版)
204
6
lambda
表达式
lambda
表达式(简称
lambda
式)能成为
C++
中极具颠覆性的语言特性,不免让人
感觉有些不可思议,因为它们并没有给语言注入新的表达力。任何
lambda
式能做到
的,你都能手工做到,无非要费力多打几个字。但是
lambda
式作为一种创建函数对
象的手段,实在太过方便,所以才会对
C++
日常软件开发产生极大的影响。如果不是
有了
lambda
式,
STL
中的“
_if
”族算法(例如,
std::find_of
std::remove_if
std::count_if
等)恐怕只会使用最平凡的谓词来调用,但有了
lambda
式以后,使用
复杂谓词来调用这些算法的应用便如雨后春笋般爆发了。这种情况同样发生在能够自
定义比较函数的算法族(例如,
std::sort
std::nth_element
std:;lower_bound
等)
上。在
STL
之外,
lambda
式也能够用来为
std::sort
std::sort
(参见条款
18
条款
19
)快速创建自定义析构器,还能以同样直接的程度对谓词做特化处理来提供条
件变量给线程
API
(参见条款
39
)。在标准库之外,
lambda
式可以临时制作出回调函数、
接口适配函数或是语境相关函数的特化版本以供一次性调用。有了
lambda
式的
C++
语言,确实变得更富有亲和力了。
围绕着
lambda
式的术语词汇可能比较让人迷惑。这里给出一些提醒:
lambda
表达式,顾名思义,是表达式的一种。它是源代码组成部分,比如在下
面这段代码中高亮部分就是
lambda
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

C++程序设计:原理与实践(基础篇)(原书第2版)

C++程序设计:原理与实践(基础篇)(原书第2版)

本贾尼 斯特劳斯特鲁普
C++语言导学(原书第2版)

C++语言导学(原书第2版)

本贾尼 斯特劳斯特鲁普
Go语言编程

Go语言编程

威廉·肯尼迪

Publisher Resources

ISBN: 9787519817749