目录
前言
学习C++的理由
读此书的理由
美女与野兽
科学与工程中的语言
排版惯例
致谢
关于作者
Chapter 1 C++ Basics
1.1 Our First Program
1.2 Variables
1.2.1 Constants
1.2.2 Literals
1.2.3 Non-narrowing Initialization
1.2.4 Scopes
1.3 Operators
1.3.1 Arithmetic Operators
1.3.2 Boolean Operators
1.3.3 Bitwise Operators
1.3.4 Assignment
1.3.5 Program Flow
1.3.6 Memory Handling
1.3.7 Access Operators
1.3.8 Type Handling
1.3.9 Error Handling
1.3.10 Overloading
1.3.11 Operator Precedence
1.3.12 Avoid Side Effects!
1.4 Expressions and Statements
1.4.1 Expressions
1.4.2 Statements
1.4.3 Branching
1.4.4 Loops
1.4.5 goto
1.5 Functions
1.5.1 Arguments
1.5.2 Returning Results
1.5.3 Inlining
1.5.4 Overloading
1.5.5 main Function
1.6 Error Handling
1.6.1 Assertions
1.6.2 Exceptions
1.6.3 Static Assertions
1.7 I/O
1.7.1 Standard Output
1.7.2 Standard Input
1.7.3 Input/Output with Files
1.7.4 Generic Stream Concept
1.7.5 Formatting
1.7.6 Dealing with I/O Errors
1.8 Arrays, Pointers, and References
1.8.1 Arrays
1.8.2 Pointers
1.8.3 Smart Pointers
1.8.4 References
1.8.5 Comparison between Pointers and References
1.8.6 Do Not Refer to Outdated Data!
1.8.7 Containers for Arrays
1.9 Structuring Software Projects
1.9.1 Comments
1.9.2 Preprocessor Directives
1.10 Exercises
1.10.1 Age
1.10.2 Arrays and Pointers
1.10.3 Read the Header of a Matrix Market File
Chapter 2 Classes
2.1 Program for Universal Meaning Not for Technical Details
2.2 Members
2.2.1 Member Variables
2.2.2 Accessibility
2.2.3 AccessOperators
2.2.4 The Static Declarator for Classes
2.2.5 Member Functions
2.3 Setting Values: Constructors and Assignments
2.3.1 Constructors
2.3.2 Assignment
2.3.3 Initializer Lists
2.3.4 Uniform Initialization
2.3.5 Move Semantics
2.4 Destructors
2.4.1 Implementation Rules
2.4.2 Dealing with Resources Properly
2.5 Method Generation Résumé
2.6 Accessing Member Variables
2.6.1 Access Functions
2.6.2 Subscript Operator
2.6.3 Constant Member Functions
2.6.4 Reference-Qualified Members
2.7 Operator Overloading Design
2.7.1 Be Consistent!
2.7.2 Respect the Priority
2.7.3 Member or Free Function
2.8 Exercises
2.8.1 Polynomial
2.8.2 Move Assignment
2.8.3 Initializer List
2.8.4 Resource Rescue
Chapter 3 Generic Programming
3.1 Function Templates
3.1.1 Instantiation
3.1.2 Parameter Type Deduction
3.1.3 Dealing with Errors in Templates
3.1.4 Mixing Types
3.1.5 Uniform Initialization
3.1.6 Automatic return Type
3.2 Namespaces and Function Lookup
3.2.1 Namespaces
3.2.2 Argument-Dependent Lookup
3.2.3 Namespace Qualification or ADL
3.3 Class Templates
3.3.1 A Container Example
3.3.2 Designing Uniform Class and Function Interfaces
3.4 Type Deduction and Definition
3.4.1 Automatic Variable Type
3.4.2 Type of an Expression
3.4.3 decltype(auto)
3.4.4 Defining Types
3.5 A Bit of Theory on Templates: Concepts
3.6 Template Specialization
3.6.1 Specializing a Class for One Type
3.6.2 Specializing and Overloading Functions
3.6.3 Partial Specialization
3.6.4 Partially Specializing Functions
3.7 Non-Type Parameters for Templates
3.8 Functors
3.8.1 Function-like Parameters
3.8.2 Composing Functors
3.8.3 Recursion
3.8.4 Generic Reduction
3.9 Lambda
3.9.1 Capture
3.9.2 Capture by Value
3.9.3 Capture by Reference
3.9.4 Generalized Capture
3.9.5 Generic Lambdas
3.10 Variadic Templates
3.11 Exercises
3.11.1 String Representation
3.11.2 String Representation of Tuples
3.11.3 Generic Stack
3.11.4 Iterator of a Vector
3.11.5 Odd Iterator
3.11.6 Odd Range
3.11.7 Stack of bool
3.11.8 Stack with Custom Size
3.11.9 Deducing Non-type Template Arguments
3.11.10 Trapezoid Rule
3.11.11 Functor
3.11.12 Lambda
3.11.13 Implement make_unique
Chapter 4 Libraries
4.1 Standard Template Library
4.1.1 Introductory Example
4.1.2 Iterators
4.1.3 Containers
4.1.4 Algorithms
4.1.5 Beyond Iterators
4.2 Numerics
4.2.1 Complex Numbers
4.2.2 Random Number Generators
4.3 Meta-programming
4.3.1 Limits
4.3.2 Type Traits
4.4 Utilities
4.4.1 Tuple
4.4.2 function
4.4.3 Reference Wrapper
4.5 The Time Is Now
4.6 Concurrency
4.7 Scientific Libraries Beyond the Standard
4.7.1 Other Arithmetics
4.7.2 Interval Arithmetic
4.7.3 Linear Algebra
4.7.4 Ordinary Differential Equations
4.7.5 Partial Differential Equations
4.7.6 Graph Algorithms
4.8 Exercises
4.8.1 Sorting by Magnitude
4.8.2 STL Container
4.8.3 Complex Numbers
Chapter 5 Meta-Programming
5.1 Let the Compiler Compute
5.1.1 Compile-Time Functions
5.1.2 Extended Compile-Time Functions
5.1.3 Primeness
5.1.4 How Constant Are Our Constants?
5.2 Providing and Using Type Information
5.2.1 Type Traits
5.2.2 Conditional Exception Handling
5.2.3 A const-Clean View Example
5.2.4 Standard Type Traits
5.2.5 Domain-Specific Type Properties
5.2.6 enable-if
5.2.7 Variadic Templates Revised
5.3 Expression Templates
5.3.1 Simple Operator Implementation
5.3.2 An Expression Template Class
5.3.3 Generic Expression Templates
5.4 Meta-Tuning: Write Your Own Compiler Optimization
5.4.1 Classical Fixed-Size Unrolling
5.4.2 Nested Unrolling
5.4.3 Dynamic Unrolling–Warm-up
5.4.4 Unrolling Vector Expressions
5.4.5 Tuning an Expression Template
5.4.6 Tuning Reduction Operations
5.4.7 Tuning Nested Loops
5.4.8 Tuning Résumé
5.5 Exercises
5.5.1 Type Traits
5.5.2 Fibonacci Sequence
5.5.3 Meta-Program for Greatest Common Divisor
5.5.4 Vector Expression Template
5.5.5 Meta-List
Chapter 6 Object-Oriented Programming
6.1 Basic Principles
6.1.1 Base and Derived Classes
6.1.2 Inheriting Constructors
6.1.3 Virtual Functions and Polymorphic Classes
6.1.4 Functors via Inheritance
6.2 Removing Redundancy
6.3 Multiple Inheritance
6.3.1 Multiple Parents
6.3.2 Common Grandparents
6.4 Dynamic Selection by Sub-typing
6.5 Conversion
6.5.1 Casting between Base and Derived Classes
6.5.2 const-Cast
6.5.3 Reinterpretation Cast
6.5.4 Function-Style Conversion
6.5.5 Implicit Conversions
6.6 CRTP
6.6.1 A Simple Example
6.6.2 A Reusable Access Operator
6.7 Exercises
6.7.1 Non-redundant Diamond Shape
6.7.2 Inheritance Vector Class
6.7.3 Clone Function
Chapter 7 Scientific Projects
7.1 Implementation of ODE Solvers
7.1.1 Ordinary Differential Equations
7.1.2 Runge-Kutta Algorithms
7.1.3 Generic Implementation
7.1.4 Outlook
7.2 Creating Projects
7.2.1 Build Process
7.2.2 Build Tools
7.2.3 Separate Compilation
7.3 Some Final Words
Appendix A Clumsy Stuff
A.1 More Good and Bad Scientific Software
A.2 Basics in Detail
A.2.1 More about Qualifying Literals
A.2.2 static Variables
A.2.3 More about if
A.2.4 Duff’s Device
A.2.5 More about main
A.2.6 Assertion or Exception?
A.2.7 Binary I/O
A.2.8 C-Style I/O
A.2.9 Garbarge Collection
A.2.10 Trouble with Macros
A.3 Real-World Example: Matrix Inversion
A.4 Class Details
A.4.1 Pointer to Member
A.4.2 More Initialization Examples
A.4.3 Accessing Multi-dimensional Arrays
A.5 Method Generation
A.5.1 Controlling the Generation
A.5.2 Generation Rules
A.5.3 Pitfalls and Design Guides
A.6 Template Details
A.6.1 Uniform Initialization
A.6.2 Which Function Is Called?
A.6.3 Specializing for Specific Hardware
A.6.4 Variadic Binary I/O
A.7 Using std::vector in C++03
A.8 Dynamic Selection in Old Style
A.9 Meta-Programming Details
A.9.1 First Meta-Program in History
A.9.2 Meta-Functions
A.9.3 Backward-Compatible Static Assertion
A.9.4 Anonymous Type Parameters
A.9.5 Benchmark Sources of Dynamic Unrolling
A.9.6 Benchmark for Matrix Product
Appendix B Programming Tools
B.1 gcc
B.2 Debugging
B.2.1 Text-Based Debugger
B.2.2 Debugging with Graphical Interface: DDD
B.3 Memory Analysis
B.4 gnuplot
B.5 Unix, Linux, and Mac OS
Appendix C Language Definitions
C.1 Value Categories
C.2 Operator Overview
C.3 Conversion Rules
C.3.1 Promotion
C.3.2 Other Conversions
C.3.3 Usual Arithmetic Conversions
C.3.4 Narrowing
Bibliography
Index
· · · · · · (
收起)