注冊(cè) | 登錄讀書(shū)好,好讀書(shū),讀好書(shū)!
讀書(shū)網(wǎng)-DuShu.com
當(dāng)前位置: 首頁(yè)出版圖書(shū)科學(xué)技術(shù)計(jì)算機(jī)/網(wǎng)絡(luò)軟件與程序設(shè)計(jì)深度探索C++14

深度探索C++14

深度探索C++14

定 價(jià):¥128.00

作 者: [德] Peter Gottschling(彼得?哥特史林) 著,吳野 譯
出版社: 電子工業(yè)出版社
叢編項(xiàng):
標(biāo) 簽: 暫缺

購(gòu)買(mǎi)這本書(shū)可以去


ISBN: 9787121354984 出版時(shí)間: 2020-07-01 包裝: 平裝
開(kāi)本: 16開(kāi) 頁(yè)數(shù): 500 字?jǐn)?shù):  

內(nèi)容簡(jiǎn)介

  本書(shū)從傳統(tǒng)的Hello World開(kāi)始,先介紹了語(yǔ)言入門(mén)C++所必須的基本要素(如表達(dá)式、語(yǔ)句、聲明);再到和程序組織有關(guān)的函數(shù)、類(lèi);然后深入探討了C++所支持的泛型編程、元編程和面向?qū)ο蟮炔煌幊谭妒?,并且提供了很多的例子可以讓讀者仔細(xì)體會(huì)它們之間的聯(lián)系、區(qū)別和適用場(chǎng)景;最后再以一個(gè)中型項(xiàng)目為例介紹了一些大型工程所必備的基礎(chǔ)知識(shí)。本書(shū)適合C++初學(xué)者、正在開(kāi)發(fā)和維護(hù)科學(xué)和工程軟件的軟件工程師,以及希望學(xué)習(xí)和理解現(xiàn)代C++機(jī)制如泛型編程和元編程的讀者。

作者簡(jiǎn)介

  Peter Gottschling 熱衷于編寫(xiě)前沿的科學(xué)計(jì)算軟件,他希望他的熱情也能感染讀者。因?yàn)槁殬I(yè)的緣故他編寫(xiě)了MTL4(矩陣模板庫(kù)4),同時(shí)也是Boost Graph Library 的作者之一。他曾在多個(gè)C++ 課程和專(zhuān)業(yè)培訓(xùn)中分享過(guò)開(kāi)發(fā)經(jīng)驗(yàn),并撰寫(xiě)了本書(shū)。譯者吳野,線上常用ID“空明流轉(zhuǎn)”。畢業(yè)后在數(shù)家IT企業(yè)工作過(guò),擁有數(shù)年軟件開(kāi)發(fā)和硬件設(shè)計(jì)經(jīng)驗(yàn)。C++為其常用編程語(yǔ)言之一,業(yè)余時(shí)間也會(huì)閱讀一些C++標(biāo)準(zhǔn)和標(biāo)準(zhǔn)提案。

圖書(shū)目錄

第1章 C++基礎(chǔ)(C++ Basics) 1
1.1 第一個(gè)程序(Our First Program) 1
1.2 變量(Variables) 4
1.2.1 常量(Constants) 7
1.2.2 字面量(Literals) 7
1.2.3 非窄化的初始化(non-narrowing initialization) 9
1.2.4 作用域(Scopes) 11
1.3 操作符(Operators) 13
1.3.1 算術(shù)操作符(Arithmetic Operators) 14
1.3.2 布爾操作符(Boolean Operators) 17
1.3.3 位操作符(Bitwise Operators) 18
1.3.4 賦值(Assignment) 19
1.3.5 程序流(Program Flow) 19
1.3.6 內(nèi)存處理(Memory Handling) 20
1.3.7 訪問(wèn)操作符(Access Operators) 21
1.3.8 類(lèi)型處理(Type Handling) 21
1.3.9 錯(cuò)誤處理(Error Handling) 21
1.3.10 重載(Overloading) 22
1.3.11 操作符優(yōu)先級(jí)(Operator Precedence) 22
1.3.12 避免副作用(Avoid Side Effects?。?22
1.4 表達(dá)式和語(yǔ)句(Expressions and Statements) 25
1.4.1 表達(dá)式(Expressions) 25
1.4.2 語(yǔ)句(Statements) 26
1.4.3 分支(Branching) 27
1.4.4 循環(huán)(Loops) 29
1.4.5 goto 33
1.5 函數(shù)(Functions) 33
1.5.1 參數(shù)(Arguments) 34
1.5.2 返回結(jié)果(Returning Results) 36
1.5.3 內(nèi)聯(lián)(Inlining) 37
1.5.4 重載(Overloading) 38
1.5.5 main函數(shù)(main Function) 40
1.6 錯(cuò)誤處理(Error Handling) 41
1.6.1 斷言(Assertions) 41
1.6.2 異常(Exceptions) 43
1.6.3 靜態(tài)斷言(Static Assertions) 48
1.7 I/O 48
1.7.1 標(biāo)準(zhǔn)輸出(Standard Output) 48
1.7.2 標(biāo)準(zhǔn)輸入(Standard Input) 49
1.7.3 文件的輸入和輸出(Input/Output with Files) 49
1.7.4 泛化的流概念(Generic Stream Concept) 50
1.7.5 格式化(Formatting) 51
1.7.6 處理輸入輸出錯(cuò)誤(Dealing with I/O Errors) 53
1.8 數(shù)組、指針和引用(Arrays, Pointers, and References) 56
1.8.1 數(shù)組(Arrays) 56
1.8.2 指針(Pointers) 58
1.8.3 智能指針(Smart Pointers) 62
1.8.4 引用(References) 65
1.8.5 指針和引用的比較(Comparison between Pointers and References) 66
1.8.6 不要引用過(guò)期數(shù)據(jù)(Do Not Refer to Outdated Data!) 67
1.8.7 數(shù)組的容器(Containers for Arrays) 67
1.9 軟件項(xiàng)目結(jié)構(gòu)化(Structuring Software Projects) 70
1.9.1 注釋?zhuān)–omments) 70
1.9.2 預(yù)編譯指示字(Preprocessor Directives) 71
1.10 練習(xí)(Exercises) 75
1.10.1 年齡(Age) 75
1.10.2 數(shù)組和指針(Arrays and Pointers) 76
1.10.3 讀取一個(gè)矩陣市場(chǎng)文件的頭部(Read the Header of a Matrix
Market File) 76
第2章 類(lèi)(Classes) 77
2.1 為普遍意義而不是技術(shù)細(xì)節(jié)編程(Program for Universal Meaning Not for
Technical Details) 77
2.2 成員(Members) 79
2.2.1 成員變量(Member Variables) 80
2.2.2 可訪問(wèn)性(Accessibility) 80
2.2.3 訪問(wèn)操作符(Access Operators) 83
2.2.4 類(lèi)的靜態(tài)聲明符(The Static Declarator for Classes) 84
2.2.5 成員函數(shù)(Member Functions) 84
2.3 設(shè)置值:構(gòu)造函數(shù)和賦值(Setting Values: Constructors and Assignments) 85
2.3.1 構(gòu)造函數(shù)(Constructors) 86
2.3.2 賦值(Assignment) 96
2.3.3 初始化器列表(Initializer Lists) 97
2.3.4 一致性初始化(Uniform Initialization) 99
2.3.5 移動(dòng)語(yǔ)義(Move Semantic) 101
2.4 析構(gòu)函數(shù)(Destructors) 105
2.4.1 實(shí)現(xiàn)準(zhǔn)則(Implementation Rules) 105
2.4.2 適當(dāng)處理資源(Dealing with Resources Properly) 106
2.5 自動(dòng)生成方法清單(Method Generation Résumé) 112
2.6 成員變量訪問(wèn)(Accessing Member Variables) 113
2.6.1 訪問(wèn)函數(shù)(Access Functions) 113
2.6.2 下標(biāo)操作符(Subscript Operator) 115
2.6.3 常量成員函數(shù)(Constant Member Functions) 116
2.6.4 引用限定的變量(Reference-Qualified Members) 117
2.7 操作符重載的設(shè)計(jì)(Operator Overloading Design) 118
2.7.1 保持一致?。˙e Consistent!) 119
2.7.2 注意優(yōu)先級(jí)(Respect the Priority) 120
2.7.3 成員函數(shù)和自由函數(shù)(Member or Free Function) 120
2.8 練習(xí)(Exercises) 123
2.8.1 多項(xiàng)式(Polynomial) 123
2.8.2 移動(dòng)賦值(Move Assignment) 123
2.8.3 初始化器列表(Initializer List) 123
2.8.4 資源管理(Resource Rescue) 124
第3章 泛型編程(Generic Programming) 125
3.1 函數(shù)模板(Function Templates) 125
3.1.1 實(shí)例化(Instantiation) 127
3.1.2 參數(shù)類(lèi)型的推導(dǎo)(Parameter Type Deduction) 128
3.1.3 在模板中處理錯(cuò)誤(Dealing with Errors in Templates) 132
3.1.4 混合類(lèi)型(Mixing Types) 133
3.1.5 一致性初始化(Uniform Initialization) 134
3.1.6 自動(dòng)返回值類(lèi)型(Automatic return Type) 134
3.2 命名空間與函數(shù)查找(Namespaces and Function Lookup) 135
3.2.1 命名空間(Namespaces) 135
3.2.2 參數(shù)相關(guān)查找(Argument-Dependent Lookup) 138
3.2.3 命名空間限定還是ADL(Namespace Qualification or ADL) 142
3.3 類(lèi)模板(Class Templates) 144
3.3.1 一個(gè)容器的范例(A Container Example) 144
3.3.2 為類(lèi)和函數(shù)設(shè)計(jì)統(tǒng)一的接口(Designing Uniform Class and
Function Interfaces) 146
3.4 類(lèi)型推導(dǎo)與定義(Type Deduction and Definition) 153
3.4.1 自動(dòng)變量類(lèi)型(Automatic Variable Type) 153
3.4.2 表達(dá)式的類(lèi)型(Type of an Expression) 154
3.4.3 decltype(auto) 155
3.4.4 定義類(lèi)型(Defining Types) 156
3.5 關(guān)于模板的一點(diǎn)點(diǎn)理論:概念(A Bit of Theory on Templates: Concepts) 158
3.6 模板特化(Template Specialization) 159
3.6.1 為單個(gè)類(lèi)型特化類(lèi)(Specializing a Class for One Type) 159
3.6.2 函數(shù)特化和重載(Specializing and Overloading Functions) 162
3.6.3 部分特化(Partial Specialization) 164
3.6.4 函數(shù)的部分特化(Partially Specializing Functions) 165
3.7 模板的非類(lèi)型參數(shù)(Non-Type Parameters for Templates) 168
3.8 仿函數(shù)(Functors) 170
3.8.1 類(lèi)似函數(shù)的參數(shù)(Function-like Parameters) 172
3.8.2 組合仿函數(shù)(Composing Functors) 173
3.8.3 遞歸(Recursion) 175
3.8.4 泛型歸納函數(shù)(Generic Reduction) 179
3.9 匿名函數(shù)(Lambda) 180
3.9.1 捕獲(Capture) 181
3.9.2 按值捕獲(Capture by Value) 181
3.9.3 按引用捕獲(Capture by Reference) 182
3.9.4 廣義捕獲(Generalized Capture) 184
3.9.5 泛型匿名函數(shù)(Generic Lambdas) 185
3.10 變參模板(Variadic Templates) 186
3.11 練習(xí)(Exercises) 188
3.11.1 字符串表示(String Representation) 188
3.11.2 元組的字符串表示(String Representation of Tuples) 188
3.11.3 泛型棧(Generic Stack) 188
3.11.4 向量的迭代器(Iterator of a Vector) 189
3.11.5 奇數(shù)迭代器(Odd Iterator) 189
3.11.6 奇數(shù)范圍(Odd Range) 189
3.11.7 bool變量的棧(Stack of bool) 190
3.11.8 自定義大小的棧(Stack with Custom Size) 190
3.11.9 非類(lèi)型模板參數(shù)的推導(dǎo)(Deducing Non-type Template Arguments) 190
3.11.10 梯形公式(Trapezoid Rule) 190
3.11.11 仿函數(shù)(Functor) 191
3.11.12 匿名函數(shù)(Lambda) 191
3.11.13 實(shí)現(xiàn)make_unique(Implement make_unique) 191
第4章 庫(kù)(Libraries) 192
4.1 標(biāo)準(zhǔn)模板庫(kù)(Standard Template Library) 193
4.1.1 入門(mén)示例(Introductory Example) 193
4.1.2 迭代器(Iterators) 194
4.1.3 容器(Containers) 199
4.1.4 算法(Algorithms) 208
4.1.5 超越迭代器(Beyond Iterators) 215
4.2 數(shù)值(Numerics) 216
4.2.1 復(fù)數(shù)(Complex Numbers) 217
4.2.2 隨機(jī)數(shù)發(fā)生器(Random Number Generators) 220
4.3 元編程(Meta-programming) 230
4.3.1 極限(Limits) 230
4.3.2 類(lèi)型特征(Type Traits) 232
4.4 支持庫(kù)(Utilities) 234
4.4.1 元組(Tuple) 235
4.4.2 函數(shù)(function) 238
4.4.3 引用包裝器(Reference Wrapper) 240
4.5 就是現(xiàn)在(The Time Is Now) 242
4.6 并發(fā)(Concurrency) 244
4.7 標(biāo)準(zhǔn)之外的科學(xué)計(jì)算程序庫(kù)(Scientific Libraries Beyond the Standard) 248
4.7.1 其他算術(shù)運(yùn)算庫(kù)(Other Arithmetics) 248
4.7.2 區(qū)間算術(shù)(Interval Arithmetic) 248
4.7.3 線性代數(shù)(Linear Algebra) 249
4.7.4 常微分方程(Ordinary Differential Equations) 249
4.7.5 偏微分方程(Partial Differential Equations) 249
4.7.6 圖論算法(Graph Algorithms) 250
4.8 練習(xí)(Exercises) 250
4.8.1 按模排序(Sorting by Magnitude) 250
4.8.2 STL容器(STL Container) 250
4.8.3 復(fù)數(shù)(Complex Numbers) 250
第5章 元編程(Meta-Programming) 252
5.1 讓編譯器進(jìn)行計(jì)算(Let the Compiler Compute) 252
5.1.1 編譯期函數(shù)(Compile-Time Functions) 253
5.1.2 擴(kuò)展的編譯期函數(shù)(Extended Compile-Time Functions) 255
5.1.3 質(zhì)數(shù)(Primeness) 257
5.1.4 此常數(shù)?彼常數(shù)?(How Constant Are Our Constants?) 259
5.2 提供和使用類(lèi)型信息(Providing and Using Type Information) 260
5.2.1 類(lèi)型特征(Type Traits) 261
5.2.2 條件異常處理(Conditional Exception Handling) 264
5.2.3 一個(gè)const整潔視圖的用例(A const-Clean View Example) 265
5.2.4 標(biāo)準(zhǔn)類(lèi)型特征(Standard Type Traits) 272
5.2.5 領(lǐng)域特定的類(lèi)型屬性(Domain-Specific Type Properties) 272
5.2.6 enable_if 274
5.2.7 新版變參模板(Variadic Templates Revised) 278
5.3 表達(dá)式模板(Expression Templates) 281
5.3.1 一個(gè)簡(jiǎn)單的操作符實(shí)現(xiàn)(Simple Operator Implementation) 281
5.3.2 一個(gè)表達(dá)式模板類(lèi)(An Expression Template Class) 285
5.3.3 泛化的表達(dá)式模板(Generic Expression Templates) 288
5.4 元優(yōu)化:編寫(xiě)你自己的編譯器優(yōu)化(Meta-Tuning: Write Your Own Compiler Optimization) 290
5.4.1 經(jīng)典的固定大小的循環(huán)展開(kāi)(Classical Fixed-Size Unrolling) 292
5.4.2 嵌套展開(kāi)(Nested Unrolling) 295
5.4.3 動(dòng)態(tài)循環(huán)展開(kāi)――熱身(Dynamic Unrolling―Warm-up) 301
5.4.4 展開(kāi)向量表達(dá)式(Unrolling Vector Expressions) 303
5.4.5 調(diào)優(yōu)表達(dá)式模板(Tuning an Expression Template) 305
5.4.6 調(diào)優(yōu)縮減運(yùn)算(Tuning Reduction Operations) 308
5.4.7 調(diào)優(yōu)嵌套循環(huán)(Tuning Nested Loops) 316
5.4.8 調(diào)優(yōu)一覽(Tuning Résumé) 322
5.5 練習(xí)(Exercises) 323
5.5.1 類(lèi)型特征(Type Traits) 323
5.5.2 Fibonacci數(shù)列(Fibonacci Sequence) 323
5.5.3 元編程版的最大公約數(shù)(Meta-Program for Greatest Common Divisor) 323
5.5.4 向量表達(dá)式模板(Vector Expression Template) 324
5.5.5 元列表(Meta-List) 325
第6章 面向?qū)ο缶幊蹋∣bject-Oriented Programming) 326
6.1 基本原則(Basic Principles) 327
6.1.1 基類(lèi)和派生類(lèi)(Base and Derived Classes) 327
6.1.2 繼承構(gòu)造(Inheriting Constructors) 331
6.1.3 虛函數(shù)和多態(tài)類(lèi)(Virtual Functions and Polymorphic Classes) 332
6.1.4 基于繼承的仿函數(shù)(Functors via Inheritance) 338
6.2 消除冗余(Removing Redundancy) 339
6.3 多重繼承(Multiple Inheritance) 340
6.3.1 多個(gè)父類(lèi)(Multiple Parents) 340
6.3.2 公共祖父(Common Grandparents) 342
6.4 通過(guò)子類(lèi)型進(jìn)行動(dòng)態(tài)選擇(Dynamic Selection by Sub-typing) 347
6.5 轉(zhuǎn)換(Conversion) 350
6.5.1 在基類(lèi)和派生類(lèi)之間轉(zhuǎn)換(Casting between Base and Derived Classes) 351
6.5.2 const轉(zhuǎn)換(const-Cast) 356
6.5.3 重解釋轉(zhuǎn)型(Reinterpretation Cast) 356
6.5.4 函數(shù)風(fēng)格的轉(zhuǎn)型(Function-Style Conversion) 357
6.5.5 隱式轉(zhuǎn)換(Implicit Conversions) 359
6.6 CRTP 359
6.6.1 一個(gè)簡(jiǎn)單的例子(A Simple Example) 360
6.6.2 一個(gè)可復(fù)用的訪問(wèn)操作符(A Reusable Access Operator) 361
6.7 練習(xí)(Exercises) 364
6.7.1 無(wú)冗余的菱形繼承(Non-redundant Diamond Shape) 364
6.7.2 繼承向量類(lèi)(Inheritance Vector Class) 364
6.7.3 克隆函數(shù)(Clone Function) 364
第7章 科學(xué)計(jì)算項(xiàng)目(Scientific Projects) 365
7.1 常微分方程解算器的實(shí)現(xiàn)(Implementation of ODE Solvers) 365
7.1.1 常微分方程(Ordinary Differential Equations) 366
7.1.2 龍格-庫(kù)塔法(Runge-Kutta Algorithms) 368
7.1.3 泛型實(shí)現(xiàn)(Generic Implementation) 369
7.1.4 展望(Outlook) 376
7.2 創(chuàng)建工程(Creating Projects) 377
7.2.1 構(gòu)建過(guò)程(Build Process) 378
7.2.2 構(gòu)建工具(Build Tools) 382
7.2.3 分離編譯(Separate Compilation) 386
7.3 最終的話(Some Final Words) 391
附錄A 雜談(Clumsy Stuff) 393
A.1 更多好的或者不好的軟件(More Good and Bad Scientific Software) 393
A.2 細(xì)節(jié)中的基礎(chǔ)(Basics in Detail) 400
A.2.1 關(guān)于字面量修飾的其他事項(xiàng)(More about Qualifying Literals) 400
A.2.2 靜態(tài)變量(static Variables) 401
A.2.3 關(guān)于if的其他事項(xiàng)(More about if) 402
A.2.4 達(dá)夫設(shè)備(Duff’s Device) 404
A.2.5 關(guān)于main的其他事項(xiàng)(More about main) 404
A.2.6 異常還是斷言?(Assertion or Exception?) 405
A.2.7 二進(jìn)制I/O(Binary I/O) 406
A.2.8 C風(fēng)格的I/O(C-Style I/O) 407
A.2.9 垃圾收集(Garbage Collection) 408
A.2.10 宏的麻煩(Trouble with Macros) 409
A.3 現(xiàn)實(shí)世界的用例:矩陣求逆(Real-World Example: Matrix Inversion) 411
A.4 類(lèi)的一些細(xì)節(jié)(Class Details) 421
A.4.1 指向成員的指針(Pointer to Member) 421
A.4.2 更多的初始化例子(More Initialization Examples) 422
A.4.3 多維數(shù)組的存?。ˋccessing Multi-dimensional Arrays) 423
A.5 方法的生成(Method Generation) 426
A.5.1 控制生成的代碼(Controlling the Generation) 428
A.5.2 代碼生成的規(guī)則(Generation Rules) 429
A.5.3 陷阱和設(shè)計(jì)指南(Pitfalls and Design Guides) 434
A.6 模板相關(guān)的細(xì)節(jié)(Template Details) 438
A.6.1 統(tǒng)一初始化(Uniform Initialization) 438
A.6.2 哪個(gè)函數(shù)被調(diào)用了?(Which Function Is Called?) 439
A.6.3 針對(duì)特定硬件的特化(Specializing for Specific Hardware) 442
A.6.4 變參二進(jìn)制I/O(Variadic Binary I/O) 443
A.7 使用C++03中的std::vector(Using std::vector in C++03) 444
A.8 復(fù)古風(fēng)格的動(dòng)態(tài)選擇(Dynamic Selection in Old Style) 445
A.9 元編程的一些細(xì)節(jié)(Meta-Programming Details) 446
A.9.1 歷史上的第一個(gè)元程序(First Meta-Program in History) 446
A.9.2 元函數(shù)(Meta-Functions) 448
A.9.3 向下兼容的靜態(tài)斷言(Backward-Compatible Static Assertion) 450
A.9.4 匿名類(lèi)型參數(shù)(Anonymous Type Parameters) 450
A.9.5 “動(dòng)態(tài)循環(huán)展開(kāi)”的性能基準(zhǔn)測(cè)試源碼(Benchmark Sources of
Dynamic Unrolling) 454
A.9.6 矩陣乘法的性能基準(zhǔn)測(cè)試(Benchmark for Matrix Product) 455
附錄B 編程工具(Programming Tools) 456
B.1 gcc 456
B.2 調(diào)試(Debugging) 457
B.2.1 基于文本的調(diào)試器(Text-Based Debugger) 458
B.2.2 使用圖形界面DDD進(jìn)行調(diào)試(Debugging with Graphical Interface: DDD) 460
B.3 內(nèi)存分析(Memory Analysis) 462
B.4 gnuplot 463
B.5 UNIX、Linux和macOS系統(tǒng)(UNIX, Linux, and macOS) 464
附錄C 語(yǔ)言定義(Language Definitions) 467
C.1 值類(lèi)別(Value Categories) 467
C.2 操作符概覽(Operator Overview) 468
C.3 類(lèi)型轉(zhuǎn)換規(guī)則(Conversion Rules) 470
C.3.1 類(lèi)型提升(Promotion) 471
C.3.2 其他類(lèi)型提升(Other Conversions) 471
C.3.3 常用的數(shù)值轉(zhuǎn)換(Usual Arithmetic Conversions) 472
C.3.4 窄化(Narrowing)

本目錄推薦

掃描二維碼
Copyright ? 讀書(shū)網(wǎng) www.talentonion.com 2005-2020, All Rights Reserved.
鄂ICP備15019699號(hào) 鄂公網(wǎng)安備 42010302001612號(hào)