David Vandevoorde是20多年的C++工作經(jīng)驗,C++標準委員會成員。曾因為審?!禩he C++ Programming Language》一書的草稿,獲得Bjarne Stroustrup的推薦,編寫了《C++ Solutions》。
圖書目錄
Preface Acknowledgments 1 About This Book 1.1 What You Should Know Before Reading This Book 1.2 Overall Structure of the Book 1.3 How to Read This Book 1.4 Some Remarks About Programming Style 1.5 The Standard versus Reality 1.6 Example Code and Additional Informations 1.7 Feedback Part I: The Basics 2 Function Templates 2.1 A First Look at Function Templates 2.1.1 Defining the Template 2.1.2 Using the Template 2.2 Argument Deduction 2.3 Template Parameters 2.4 Overloading Function Templates 2.5 Summary 3 Class Templates 3.1 Implementation of Class Template Stack 3.1.1 Declaration of Class Templates 3.1.2 Implementation of Member Functions 3.2 Use of Class Template Stack 3.3 Specializations of Class Templates 3.4 Partial Specialization 3.5 Default Template Arguments 3.6 Summary 4 Nontype Template Parameters 4.1 Nontype Class Template Parameters 4.2 Nontype Function Template Parameters 4.3 Restrictions for Nontype Template Parameters 4.4 Summary 5 Tricky Basics 5.1 Keyword typename 5.2 Using this-> 5.3 Member Templates 5.4 Template Template Parameters 5.5 Zero Initialization 5.6 Using String Literals as Arguments for Function Templates 5.7 Summary 6 Using Templates in Practice 6.1 The Inclusion Model 6.1.1 Linker Errors 6.1.2 Templates in Header Files 6.2 Explicit Instantiation 6.2.1 Example of Explicit Instantiation 6.2.2 Combining the Inclusion Model and Explicit Instantiation 6.3 The Separation Model 6.3.1 The Keyword export 6.3.2 Limitations of the Separation Model 6.3.3 Preparing for the Separation Model 6.4 Templates and inline 6.5 Precompiled Headers 6.6 Debugging Templates 6.6.1 Decoding the Error Novel 6.6.2 Shallow Instantiation 6.6.3 Long Symbols 6.6.4 Tracers 6.6.5 Oracles 6.6.6 Archetypes 6.7 Aftemotes 6.8 Summary 7 Basic Template Terminology 7.1 "Class Template" or "Template Class"? 7.2 Instantiation and Specialization 7.3 Declarations versus Definitions 7.4 The One-Definition Rule 7.5 Template Arguments versus Template Parameters Part II: Templates in Depth Fundamentals in Depth 8.1 Parameterized Declarations 8.1.1 Virtual Member Functions 8.1.2 Linkage of Templates 8.1.3 Primary Templates 8.2 Template Parameters 8.2.1 Type Parameters 8.2.2 Nontype Parameters 8.2.3 Template Template Parameters 8.2.4 Default Template Arguments 8.3 Template Arguments 8.3.1 Function Template Arguments 8.3.2 Type Arguments 8.3.3 Nontype Arguments 8.3.4 Template Template Arguments 8.3.5 Equivalence 8.4 Friends 8.4.1 Friend Functions 8.4.2 Friend Templates 8.5 Aftemotes 9 Names in Templates 9.1 Name Taxonomy 9.2 Looking Up Names 9.2.1 Argument-Dependent Lookup 9.2.2 Friend Name Injection 9.2.3 Injected Class Names 9.3 Parsing Templates 9.3.1 Context Sensitivity in Nontemplates 9.3.2 Dependent Names of Types 9.3.3 Dependent Names of Templates 9.3.4 Dependent Names in Using-Declarations 9.3.5 ADL and Explicit Template Arguments 9.4 Derivation and Class Templates 9.4.1 Nondependent Base Classes 9.4.2 Dependent Base Classes 9.5 Afternotes 10 Instantiation 10.1 On-Demand Instantiation 10.2 Lazy Instantiation 10.3 The C++ Instantiation Model 10.3.1 Two-Phase Lookup 10.3.2 Points of Instantiation 10.3.3 The Inclusion and Separation Models 10.3.4 Looking Across Translation Units 10.3.5 EXamples 10.4 Implementation Schemes 10.4.1 Greedy Instantiation 10.4.2 Queried Instantiation 10.4.3 Iterated Instantiation 10.5 Explicit Instantiation 10.6 Afternotes 11 Template Argument Deduction 11.1 The Deduction Process 11.2 Deduced Contexts 11.3 Special Deduction Situations 11.4 Allowable Argument Conversions 11.5 Class Template Parameters 11.6 Default Call Arguments 11.7 The Barton-Nackman Trick 11.8 Afternotes 12 Specialization and Overloading 12.1 When "Generic Code" Doesn't Quite Cut It 12.1.1 Transparent Customization 12.1.2 Semantic Transparency 12.2 Overloading Function Templates 12.2.1 Signatures 12.2.2 Partial Ordering of Overloaded Function Templates 12.2.3 Formal Ordering Rules 12.2.4 Templates and Nontemplates 12.3 Explicit Specialization 12.3.1 Full Class Template Specialization 12.3.2 Full Function Template Specialization 12.3.3 Full Member Specialization 12.4 Partial Class Template Specialization 12.5 Aftemotes 13 Future Directions 13.1 The Angle Bracket Hack 13.2 Relaxed typename Rules 13.3 Default Function Template Arguments 13.4 String Literal and Floating-Point Template Arguments 13.5 Relaxed Matching of Template Template Parameters 13.6 Typedef Templates 13.7 Partial Specialization of Function Templates 13.8 The typeof Operator 13.9 Named Template Arguments 13.10 Static Properties 13.11 Custom Instantiation Diagnostics 13.12 Overloaded Class Templates 13.13 List Parameters 13.14 Layout Control 13.15 Initializer Deduction 13.16 Function Expressions 13.17 Afternotes Part III: Templates and Design 14 The Polymorphic Power of Templates 14.1 Dynamic Polymorphism 14.2 Static Polymorphism 14.3 Dynamic versus Static Polymorphism 14.4 New Forms of Design Patterns 14.5 Generic Programming 14.6 Afternotes 15 Traits and Policy Classes 15.1 An Example: Accumulating a Sequence 15.1.1 Fixed Traits 15.1.2 Value Traits 15.1.3 Parameterized Traits 15.1.4 Policies and Policy Classes 15.1.5 Traits and Policies: What's the Difference? 15.1.6 Member Templates versus Template Template Parameters 15.1.7 Combining Multiple Policies and/or Traits 15.1.8 Accumulation with General Iterators 15.2 Type Functions 15.2.1 Determining Element Types 15.2.2 Determining Class Types 15.2.3 References and Qualifiers 15.2.4 Promotion Traits 15.3 Policy Traits 15.3.1 Read-only Parameter Types 15.3.2 Copying, Swapping, and Moving 15.4 Afternotes 16 Templates and Inheritance 16.1 Named Template Arguments 16.2 The Empty Base Class Optimization (EBCO) 16.2.1 Layout Principles 16.2.2 Members as Base Classes 16.3 The Curiously Recurring Template Pattern (CRTP) 16.4 Parameterized Virtuality 16.5 Afternotes 17 Metaprograms 17.1 A First Example of a Metaprogram 17.2 Enumeration Values versus Static Constants 17.3 A Second Example: Computing the Square Root 17.4 Using Induction Variables 17.5 Computational Completeness 17.6 Recursive Instantiation versus Recursive Template Arguments 17.7 Using Metaprograms to Unroll Loops 17.8 Afternotes 18 Expression Templates 18.1 Temporaries and Split Loops 18.2 Encoding Expressions in Template Arguments 18.2.1 Operands of the Expression Templates 18.2.2 The Array Type 18.2.3 The Operators 18.2.4 Review 18.2.5 Expression Templates Assignments 18.3 Performance and Limitations of Expression Templates 18.4 Afternotes Part IV: Advanced Applications 19 Type Classification 19.1 Determining Fundamental Types 19.2 Determining Compound Types 19.3 Identifying Function Types 19.4 Enumeration Classification with Overload Resolution 19.5 Determining Class Types 19.6 Putting It All Together 19.7 Afternotes 20 Smart Pointers 20.1 Holders and Trules 20.1.1 Protecting Against Exceptions 20.1.2 Holders 20.1.3 Holders as Members 20.1.4 Resource Acquisition Is Initialization 20.1.5 Holder Limitations 20.1.6 Copying Holders 20.1.7 Copying Holders Across Function Calls 20.1.8 Trules 20.2 Reference Counting 20.2.1 Where Is the Counter? 20.2.2 Concurrent Counter Access 20.2.3 Destruction and Deallocation 20.2.4 The CountingPtr Template 20.2.5 A Simple Noninvasive Counter 20.2.6 A Simple Invasive Counter Template 20.2.7 Constness 20.2.8 Implicit Conversions 20.2.9 Comparisons 20.3 Afternotes 21 Tuples 21.1 Duos 21.2 Recursive Duos 21.2.1 Number of Fields 21.2.2 Type of Fields 21.2.3 Value of Fields 21.3 Tuple Construction 21.4 Afternotes 22 Function Objects and Callbacks 22.1 Direct, Indirect, and Inline Calls 22.2 Pointers and References to Functions 22.3 Pointer-to-Member Functions 22.4 Class Type Functors 22.4.1 A First Example of Class Type Functors 22.4.2 Type of Class Type Functors 22.5 Specifying Functors 22.5.1 Functors as Template Type Arguments 22.5.2 Functors as Function Call Arguments 22.5.3 Combining Function Call Parameters and Template Type Parameters 22.5.4 Functors as Nontype Template Arguments 22.5.5 Function Pointer Encapsulation 22.6 Introspection 22.6.1 Analyzing a Functor Type 22.6.2 Accessing Parameter Types 22.6.3 Encapsulating Function Pointers 22.7 Function Object Composition 22.7.1 Simple Composition 22.7.2 Mixed Type Composition 22.7.3 Reducing the Number of Parameters 22.8 Value Binders 22.8.1 Selecting the Binding 22.8.2 Bound Signature 22.8.3 Argument Selection 22.8.4 Convenience Functions 22.9 Functor Operations: A Complete Implementation 22.10 Afternotes Appendixes A The One-Definition Rule A.1 Translation Units A.2 Declarations and Definitions A.3 The One-Definition Rule in Detail A.3.1 One-per-Program Constraints A.3.2 One-per-Translation Unit Constraints A.3.3 Cross-Translation Unit Equivalence Constraints B Overload Resolution B.1 When Does Overload Resolution Kick In? B.2 Simplified Overload Resolution B.2.1 The Implied Argument for Member Functions B.2.2 Refining the Perfect Match B.3 Overloading Details B.3.1 Prefer Nontemplates B.3.2 Conversion Sequences B.3.3 Pointer Conversions B.3.4 Functors and Surrogate Functions B.3.5 Other Overloading Contexts Bibliography Newsgroups Books and Web Sites Glossary Index