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++(中文版)
15
1
型别推导
C++98
仅有一套型别推导规则,用于函数模板。
C++11
对这套规则进行了一些改动,
并且增加了两套规则,一套用于
auto
,另一套用于
decltype
。后来,
C++14
又扩展
了能够运用
auto
decltype
的语境。型别推导应用范围的不断普及,使得人们不必
再去写下那些不言自明或是完全冗余的型别。它还让
C++
软件获得更高的适应性,因
为在源代码的一个地方对一个型别实施的改动,可以自动通过型别推导传播到其他地
方。然而,它也有可能导致写出来的代码较难看懂,因为编译器推导出的型别,可能
不像我们所认为的那样显而易见。
想要使用现代
C++
高效编程,就离不开对于型别推导操作的坚实理解。型别推导涉
及的语境实在不胜枚举:在函数模板的调用中,在
auto
现身的大多数场景中,在
decltype
表达式中,特别是在
C++14
中那个神秘莫测的
decltype(auto)
结构中。
本章讨论的是每个
C++
开发工程师都需要了解的有关型别推导的知识。本章解释了模
板型别推导如何运作,
auto
的型别推导如何构建在此运作规则之上,以及
decltype
独特的型别推导规则。本章还教你如何迫使编译器来展示其型别推导的结果,从而让
你确信该结果如你所愿。
条款
1
:理解模板型别推导
如果一个复杂系统的用户对于该系统的运作方式一无所知,然而却对其提供的服务表
示满意,这就充分说明系统设计得好。如果从这样的角度来看,
C++
的模板型别推导
取得了极大的成功。成百上千的程序员都在向函数模板传递实参,并拿到了完全满意
16
1
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

流畅的Python(第2版)

流畅的Python(第2版)

Luciano Ramalho
Go语言编程

Go语言编程

威廉·肯尼迪

Publisher Resources

ISBN: 9787519817749