譯序by 侯捷 i</font><br>譯序by 於春景 iii</font><br>目錄 v</font><br>序言by Scott Meyers xi</font><br>序言by John Vlissides xv</font><br>前言 xvii</font><br>致謝 xxi</font><br>第一篇 技術(Techniques) 1</font><br>第1章 基于Policy的Class設計(Policy-Based Class Design) 3</font><br>1.1 軟件設計的多樣性(Multiplicity) 3</font><br>1.2 全功能型(Do-It-All)接口的失敗 4</font><br>1.3 多重繼承(Multiple Inheritance)是救世主? 5</font><br>1.4 Templates帶來曙光 6</font><br>1.5 Policies和Policy Classes 7</font><br>1.6 更豐富的Policies 12</font><br>1.7 Policy Classes的析構函數(shù)(Destructors) 12</font><br>1.8 通過不完全具現(xiàn)化(Incomplete Instantiation)</font><br>而獲得的選擇性機能(Optional Functionality) 13</font><br>1.9 結合Policy Classes 14</font><br>1.10 以Policy Classes定制結構 16</font><br>1.11 Policies的兼容性 17</font><br>1.12 將一個Class分解為一堆Policies 19</font><br>1.13 摘要 20</font><br></font><br>第2章 技術(Techniques) 23</font><br>2.1 編譯期(Compile-Time)Assertions 23</font><br>2.2 Partial Template Specialization(模板偏特化) 26</font><br>2.3 局部類(Local Classes) 28 </font><br>2.4 常整數(shù)映射為型別(Mapping Integral Constants to Types) 29</font><br>2.5 型別對型別的映射(Type-to-Type Mapping) 31</font><br>2.6 型別選擇(Type Selection) 33</font><br>2.7 編譯期間偵測可轉換性(Convertibility)和繼承性(Inheritance) 34</font><br>2.8 type_info的一個外覆類(Wrapper) 37</font><br>2.9 NullType和EmptyType 39</font><br>2.10 Type Traits 40</font><br>2.11 摘要 46</font><br>第3章 Typelists 49</font><br>3.1 Typelists的必要性 49</font><br>3.2 定義Typelists 51</font><br>3.3 將Typelist的生成線性化(linearizing) 52</font><br>3.4 計算長度 53</font><br>3.5 間奏曲 54</font><br>3.6 索引式訪問(Indexed Access) 55</font><br>3.7 查找Typelists 56</font><br>3.8 附加元素至Typelists 57</font><br>3.9 移除Typelist中的某個元素 58</font><br>3.10 移除重復元素(Erasing Duplicates) 59</font><br>3.11 取代Typelist中的某個元素 60</font><br>3.12 為Typelists局部更換次序(Partially Ordering) 61</font><br>3.13 運用Typelists自動產生Class es 64</font><br>3.14 摘要 74</font><br>3.15 Typelist要點概覽 75</font><br>第4章 小型對象分配技術(Small-Object Allocation) 77</font><br>4.1 缺省的Free Store分配器 78</font><br>4.2 內存分配器的工作方式 78</font><br>4.3 小型對象分配器(Small-Object Allocator) 80</font><br>4.4 Chunks(大塊內存) 81</font><br>4.5 大小一致(Fixed-Size)的分配器 84</font><br>4.6 SmallObjAllocator Class 87</font><br>4.7 帽子下的戲法 89</font><br>4.8 簡單,復雜,終究還是簡單 92</font><br>4.9 使用細節(jié) 93</font><br>4.10 摘要 94</font><br>4.11 小型對象分配器(Small-Object Allocator)要點概覽 94</font><br>第二篇 組件(Components) 97</font><br>第5章 泛化仿函數(shù)(Generalized Functors) 99</font><br>5.1 Command設計模式 100</font><br>5.2 真實世界中的Command 102</font><br>5.3 C++ 中的可呼叫體(Callable Entities) 103</font><br>5.4 Functor Class Template骨干 104</font><br>5.5 實現(xiàn)“轉發(fā)式”(Forwarding)Functor::operator() 108</font><br>5.6 處理仿函數(shù) 110</font><br>5.7 做一個,送一個 112</font><br>5.8 引數(shù)(Argument)和返回型別(Return Type)的轉換 114</font><br>5.9 處理pointer to member function(成員函數(shù)指針) 115</font><br>5.10 綁定(Binding) 119</font><br>5.11 將請求串接起來(Chaining Requests) 122</font><br>5.12 現(xiàn)實世界中的問題之1:轉發(fā)式函數(shù)的成本 122</font><br>5.13 現(xiàn)實世界中的問題之2:Heap分配 124</font><br>5.14 通過Functor實現(xiàn)Undo和Redo 125</font><br>5.15 摘要 126</font><br>5.16 Functor要點概覽 126</font><br>第6章 Singletons(單件)實現(xiàn)技術 129</font><br>6.1 靜態(tài)數(shù)據 + 靜態(tài)函數(shù) != Singleton 130</font><br>6.2 用以支持Singleton的一些C++ 基本手法 131</font><br>6.3 實施“Singleton的唯一性” 132</font><br>6.4 摧毀Singleton 133</font><br>6.5 Dead(失效的)Reference問題 135</font><br>6.6 解決Dead Reference問題(I):Phoenix Singleton 137</font><br>6.7 解決Dead Reference問題(II):帶壽命的Singletons 139</font><br>6.8 實現(xiàn)“帶壽命的Singletons” 142</font><br>6.9 生活在多線程世界 145</font><br>6.10 將一切組裝起來 148</font><br>6.11 使用SingletonHolder 153</font><br>6.12 摘要 155</font><br>6.13 SingletonHolder Class Template要點概覽 155</font><br></font><br>第7章 Smart Pointers(智能指針) 157</font><br>7.1 Smart Pointers基礎 157</font><br>7.2 交易 158</font><br>7.3 Smart Pointers的存儲 160</font><br>7.4 Smart Pointer的成員函數(shù) 161</font><br>7.5 擁有權(Ownership)管理策略 163</font><br>7.6 Address-of(取址)操作符 170</font><br>7.7 隱式轉換(Implicit Conversion)至原始指針型別 171</font><br>7.8 相等性(Equality)和不等性(Inequality) 173</font><br>7.9 次序比較(Ordering Comparisons) 178</font><br>7.10 檢測及錯誤報告(Checking and Error Reporting) 181</font><br>7.11 Smart Pointers to const和const Smart Pointers 182</font><br>7.12 Arrays 183</font><br>7.13 Smart Pointers和多線程(Multithreading) 184</font><br>7.14 將一切組裝起來 187</font><br>7.15 摘要 194</font><br>7.16 SmartPtr要點概覽 194</font><br>第8章 Object Factories(對象工廠) 197</font><br>8.1 為什么需要Object Factories 198</font><br>8.2 Object Factories in C++:Classes和Objects 200</font><br>8.3 實現(xiàn)一個Object Factory 201</font><br>8.4 型別標識符(Type Identifiers) 206</font><br>8.5 泛化(Generalization) 207</font><br>8.6 細節(jié)瑣務 210</font><br>8.7 Clone Factories(克隆工廠、翻制工廠、復制工廠) 211</font><br>8.8 通過其他泛型組件來使用Object Factories 215</font><br>8.9 摘要 216</font><br>8.10 Factory Class Template要點概覽 216</font><br>8.11 CloneFactory Class Template要點概覽 217</font><br>第9章 Abstract Factory(抽象工廠) 219</font><br>9.1 Abstract Factory扮演的體系結構角色(Architectural role) 219</font><br>9.2 一個泛化的Abstract Factory接口 223</font><br>9.3 實作出AbstractFactory 226</font><br>9.4 一個Prototype-Based Abstract Factory實作品 228</font><br>9.5 摘要 233</font><br>9.6 AbstractFactory和ConcreteFactory要點概覽 233</font><br></font><br>第10章 Visitor(訪問者、視察者) 235</font><br>10.1 Visitor 基本原理 235</font><br>10.2 重載(Overloading):Catch-All函數(shù) 242</font><br>10.3 一份更加精煉的實作品:Acyclic Visitor 243</font><br>10.4 Visitor之泛型實作 248</font><br>10.5 再論 "Cyclic" Visitor 255</font><br>10.6 變化手段 258</font><br>10.7 摘要 260</font><br>10.8 Visitor泛型組件要點概覽 261</font><br>第11章 Multimethods 263</font><br>11.1 什么是Multimethods? 264</font><br>11.2 何時需要Multimethods? 264</font><br>11.3 Double Switch-on-Type:暴力法 265</font><br>11.4 將暴力法自動化 268</font><br>11.5 暴力式Dispatcher 的對稱性 273</font><br>11.6 對數(shù)型(Logarithmic)Double Dispatcher 276</font><br>11.7 FnDispatcher 和對稱性 282</font><br>11.8 Double Dispatch(雙重分派)至仿函數(shù)(Functors) 282</font><br>11.9 引數(shù)的轉型:static_cast或dynamic_cast? 285</font><br>11.10 常數(shù)時間的Multimethods:原始速度(Raw Speed) 290</font><br>11.11 將BasicDispatcher 和BasicFastDispatcher當做Policies 293</font><br>11.12 展望 294</font><br>11.13 摘要 296</font><br>11.14 Double Dispatcher要點概覽 297</font><br>附錄 一個超迷你的多線程程序庫(A Minimalist Multithreading Library) 301</font><br>A.1 多線程的反思 302</font><br>A.2 Loki的作法 303</font><br>A.3 整數(shù)型別上的原子操作(Atomic Operations) 303</font><br>A.4 Mutexes(互斥器) 305</font><br>A.5 面向對象編程中的鎖定語意(Locking Semantics) 306</font><br>A.6 可有可無的(Optional)volatile標識符 308</font><br>A.7 Semaphores, Events和其他好東西 309</font><br>A.8 摘要 309</font><br>參考書目(Bibliography) 311</font><br>索引(Index)