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++(中文版)
lambda
表达式
217
那个条款也解释说,
C++11
中有一些情况下,
std::bind
可能会是有用的,而以上就
是这些情况之一(在
C++14
中,像初始化捕获和
auto
形参这些特性可以消除那些情
况)。
要点速记
使用
C++14
的初始化捕获将对象移入闭包。
C++11
中,经由手工实现的类或
std::bind
去模拟初始化捕获。
条款
33
:对
auto&&
型别的形参使用
decltype
std::forward
泛型
lambda
式(
generic lambda
)是
C++14
最振奋人心的特性之一——
lambda
可以
在形参规格中使用
auto
。这个特性的实现十分直截了当:闭包类中的
operator()
模板实现。例如,给定下述
lambda
式:
auto f = [](
auto
x){ return func(normalize(x)); };
则闭包类的函数调用运算符如下所示:
class
SomeCompilerGeneratedClassName
{
public:
template<typename T>
// auto
型别的返回值
auto operator()(
T
x) const
//
参见条款
3
{ return func(normalize(x)); }
//
闭包类的其他功能
};
在本例中,
lambda
式对
x
实施的唯一动作就是将其转发给
normalize
。如果
normalize
区别对待左值和右值,则可说该
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