1About This Book
1.1WhyThisBook
1.2Before Reading This Book
1.3Style and Structure of the Book
1.4HowtoReadThisBook
1.5Stateof theArt
1.6Example Code and Additional Information
1.7Feedback
2Introduction to C++ and the Standard Library
2.1History of theC++Standards
2.1.1Common Questions about the C++11 Standard
2.1.2Compatibility between C++98 and C++11
2.2Complexity and Big-O Notation
3New Language Features
3.1New C++11 Language Features
3.1.1Important Minor Syntax Cleanups
3.1.2Automatic Type Deduction with auto
3.1.3Uniform Initialization and Initializer Lists
3.1.4Range-Based for Loops
3.1.5Move Semantics and Rvalue References
3.1.6NewStringLiterals
3.1.7Keyword noexcept
3.1.8Keyword constexpr
3.1.9NewTemplateFeatures
3.1.10Lambdas
3.1.11Keyword decltype
3.1.12New Function Declaration Syntax
3.1.13Scoped Enumerations
3.1.14New Fundamental Data Types
3.2Old “New” Language Features
3.2.1Explicit Initialization for Fundamental Types
3.2.2Definition of main()
4General Concepts
4.1Namespace std
4.2HeaderFiles
4.3Error and Exception Handling
4.3.1Standard Exception Classes
4.3.2Members of Exception Classes
4.3.3Passing Exceptions with Class exception_ptr
4.3.4Throwing Standard Exceptions
4.3.5Deriving from Standard Exception Classes
4.4CallableObjects
4.5Concurrency and Multithreading
4.6Allocators
5Utilities
5.1Pairs and Tuples
5.1.1Pairs
5.1.2Tuples
5.1.3I/O for Tuples
5.1.4Conversions between tuples and pairs
5.2Smart Pointers
5.2.1Class shared_ptr
5.2.2Class weak_ptr
5.2.3Misusing Shared Pointers
5.2.4Shared and Weak Pointers in Detail
5.2.5Class unique_ptr
5.2.6Class unique_ptr inDetail
5.2.7Class auto_ptr
5.2.8Final Words on Smart Pointers
5.3NumericLimits
5.4Type Traits and Type Utilities
5.4.1PurposeofTypeTraits
5.4.2TypeTraits inDetail
5.4.3ReferenceWrappers
5.4.4Function Type Wrappers
5.5Auxiliary Functions
5.5.1Processing the Minimum and Maximum
5.5.2Swapping Two Values
5.5.3Supplementary Comparison Operators
5.6Compile-Time Fractional Arithmetic with Classratio<>
5.7Clocks andTimers
5.7.1Overviewof theChronoLibrary
5.7.2Durations
5.7.3Clocks and Timepoints
5.7.4Date and Time Functions by C and POSIX
5.7.5Blocking with Timers
5.8Header Files , , and
5.8.1Definitions in
5.8.2Definitions in
5.8.3Definitions in
6The Standard Template Library
6.1STL Components
6.2Containers
6.2.1Sequence Containers
6.2.2Associative Containers
6.2.3Unordered Containers
6.2.4AssociativeArrays
6.2.5Other Containers
6.2.6Container Adapters
6.3Iterators
6.3.1Further Examples of Using Associative and UnorderedContainers
6.3.2IteratorCategories
6.4Algorithms
6.4.1Ranges
6.4.2Handling Multiple Ranges
6.5IteratorAdapters
6.5.1Insert Iterators
6.5.2StreamIterators
6.5.3Reverse Iterators
6.5.4Move Iterators
6.6User-Defined Generic Functions
6.7Manipulating Algorithms
6.7.1“Removing” Elements
6.7.2Manipulating Associative and Unordered Containers
6.7.3Algorithms versus Member Functions
6.8Functions as Algorithm Arguments
6.8.1Using Functions as Algorithm Arguments
6.8.2Predicates
6.9UsingLambdas
6.10Function Objects
6.10.1Definition of Function Objects
6.10.2Predefined Function Objects
6.10.3Binders
6.10.4Function Objects and Binders versus Lambdas
6.11Container Elements
6.11.1Requirements for Container Elements
6.11.2Value Semantics or Reference Semantics
6.12Errors and Exceptions inside the STL
6.12.1Error Handling
6.12.2Exception Handling
6.13Extending the STL
6.13.1Integrating Additional Types
6.13.2Deriving from STL Types
7STL Containers
7.1Common Container Abilities and Operations
7.1.1Container Abilities
7.1.2Container Operations
7.1.3Container Types
7.2Arrays
7.2.1Abilities of Arrays
7.2.2Array Operations
7.2.3Using arrays as C-Style Arrays
7.2.4Exception Handling
7.2.5Tuple Interface
7.2.6ExamplesofUsingArrays
7.3Vectors
7.3.1Abilities of Vectors
7.3.2Vector Operations
7.3.3Using Vectors as C-Style Arrays
7.3.4Exception Handling
7.3.5ExamplesofUsingVectors
7.3.6Class vector
7.4Deques
7.4.1Abilities of Deques
7.4.2Deque Operations
7.4.3Exception Handling
7.4.4ExamplesofUsingDeques
7.5Lists
7.5.1Abilities of Lists
7.5.2List Operations
7.5.3Exception Handling
7.5.4ExamplesofUsingLists
7.6ForwardLists
7.6.1Abilities of Forward Lists
7.6.2Forward List Operations
7.6.3Exception Handling
7.6.4ExamplesofUsingForwardLists
7.7Sets and Multisets
7.7.1Abilities of Sets and Multisets
7.7.2Set and Multiset Operations
7.7.3Exception Handling
7.7.4Examples of Using Sets and Multisets
7.7.5Example of Specifying the Sorting Criterion atRuntime
7.8Maps and Multimaps
7.8.1Abilities of Maps and Multimaps
7.8.2Map and Multimap Operations
7.8.3UsingMaps asAssociativeArrays
7.8.4Exception Handling
7.8.5Examples of Using Maps and Multimaps
7.8.6Example with Maps, Strings, and Sorting Criterion atRuntime
7.9Unordered Containers
7.9.1Abilities of Unordered Containers
7.9.2Creating and Controlling Unordered Containers
7.9.3Other Operations for Unordered Containers
7.9.4TheBucket Interface
7.9.5UsingUnorderedMaps asAssociativeArrays
7.9.6Exception Handling
7.9.7Examples of Using Unordered Containers
7.10Other STL Containers
7.10.1Strings as STL Containers
7.10.2Ordinary C-Style Arrays as STL Containers
7.11Implementing Reference Semantics
7.12When to Use Which Container
8STL Container Members in Detail
8.1Type Definitions
8.2Create, Copy, and Destroy Operations
8.3Nonmodifying Operations
8.3.1Size Operations
8.3.2Comparison Operations
8.3.3Nonmodifying Operations for Associative and UnorderedContainers
8.4Assignments
8.5Direct Element Access
8.6Operations to Generate Iterators
8.7Inserting and Removing Elements
8.7.1Inserting Single Elements
8.7.2Inserting Multiple Elements
8.7.3Removing Elements
8.7.4Resizing
8.8Special Member Functions for Lists and Forward Lists
8.8.1Special Member Functions for Lists (and ForwardLists)
8.8.2Special Member Functions for Forward Lists Only
8.9Container Policy Interfaces
8.9.1Nonmodifying Policy Functions
8.9.2Modifying Policy Functions
8.9.3Bucket Interface for Unordered Containers
8.10Allocator Support
8.10.1Fundamental Allocator Members
8.10.2Constructors with Optional Allocator Parameters
9STL Iterators
9.1HeaderFiles for Iterators
9.2IteratorCategories
9.2.1Output Iterators
9.2.2Input Iterators
9.2.3ForwardIterators
9.2.4Bidirectional Iterators
9.2.5Random-Access Iterators
9.2.6The Increment and Decrement Problem of VectorIterators
9.3Auxiliary Iterator Functions
9.3.1advance()
9.3.2next() and prev()
9.3.3distance()
9.3.4iter_swap()
9.4IteratorAdapters
9.4.1Reverse Iterators
9.4.2Insert Iterators
9.4.3StreamIterators
9.4.4Move Iterators
9.5IteratorTraits
9.5.1Writing Generic Functions for Iterators
9.6Writing User-Defined Iterators
10STL Function Objects and Using Lambdas
10.1The Concept of Function Objects
10.1.1Function Objects as Sorting Criteria
10.1.2Function Objects with Internal State
10.1.3The Return Value of for_each()
10.1.4Predicates versus Function Objects
10.2Predefined Function Objects and Binders
10.2.1Predefined Function Objects
10.2.2Function Adapters and Binders
10.2.3User-Defined Function Objects for Function Adapters
10.2.4Deprecated Function Adapters
10.3UsingLambdas
10.3.1Lambdas versus Binders
10.3.2Lambdas versus Stateful Function Objects
10.3.3Lambdas Calling Global and Member Functions
10.3.4Lambdas as Hash Function, Sorting, or EquivalenceCriterion
11STL Algorithms
11.1Algorithm Header Files
11.2Algorithm Overview
11.2.1A Brief Introduction
11.2.2Classification of Algorithms
11.3Auxiliary Functions
11.4The for_each() Algorithm
11.5Nonmodifying Algorithms
11.5.1Counting Elements
11.5.2Minimum and Maximum
11.5.3Searching Elements
11.5.4ComparingRanges
11.5.5Predicates forRanges
11.6Modifying Algorithms
11.6.1Copying Elements
11.6.2Moving Elements
11.6.3Transforming and Combining Elements
11.6.4Swapping Elements
11.6.5Assigning New Values
11.6.6ReplacingElements
11.7Removing Algorithms
11.7.1Removing Certain Values
11.7.2Removing Duplicates
11.8Mutating Algorithms
11.8.1ReversingtheOrderofElements
11.8.2Rotating Elements
11.8.3Permuting Elements
11.8.4ShufflingElements
11.8.5Moving Elements to the Front
11.8.6Partition into Two Subranges
11.9Sorting Algorithms
11.9.1Sorting All Elements
11.9.2Partial Sorting
11.9.3Sorting According to the nthElement
11.9.4Heap Algorithms
11.10Sorted-Range Algorithms
11.10.1Searching Elements
11.10.2Merging Elements
11.11Numeric Algorithms
11.11.1Processing Results
11.11.2Converting Relative and Absolute Values
12Special Containers
12.1Stacks
12.1.1TheCore Interface
12.1.2ExampleofUsingStacks
12.1.3AUser-DefinedStackClass
12.1.4Class stack<> inDetail
12.2Queues
12.2.1TheCore Interface
12.2.2ExampleofUsingQueues
12.2.3AUser-DefinedQueueClass
12.2.4Class queue<> inDetail
12.3PriorityQueues
12.3.1TheCore Interface
12.3.2ExampleofUsingPriorityQueues
12.3.3Class priority_queue<> inDetail
12.4Container Adapters in Detail
12.4.1Type Definitions
12.4.2Constructors
12.4.3Supplementary Constructors for Priority Queues
12.4.4Operations
12.5Bitsets
12.5.1ExamplesofUsingBitsets
12.5.2Class bitset inDetail
13Strings
13.1Purposeof theStringClasses
13.1.1A First Example: Extracting a Temporary Filename
13.1.2A Second Example: Extracting Words and Printing ThemBackward
13.2Description of the String Classes
13.2.1StringTypes
13.2.2Operation Overview
13.2.3Constructors andDestructor
13.2.4Strings and C-Strings
13.2.5Size andCapacity
13.2.6Element Access
13.2.7Comparisons
13.2.8Modifiers
13.2.9Substrings and String Concatenation
13.2.10Input/Output Operators
13.2.11Searching and Finding
13.2.12The Value npos
13.2.13Numeric Conversions
13.2.14Iterator Support for Strings
13.2.15Internationalization
13.2.16Performance
13.2.17Strings and Vectors
13.3StringClass inDetail
13.3.1Type Definitions and Static Values
13.3.2Create, Copy, and Destroy Operations
13.3.3Operations for Size and Capacity
13.3.4Comparisons
13.3.5Character Access
13.3.6Generating C-Strings and Character Arrays
13.3.7Modifying Operations
13.3.8Searching and Finding
13.3.9Substrings and String Concatenation
13.3.10Input/Output Functions
13.3.11Numeric Conversions
13.3.12Generating Iterators
13.3.13Allocator Support
14Regular Expressions
14.1TheRegexMatch andSearchInterface
14.2Dealing with Subexpressions
14.3Regex Iterators
14.4RegexToken Iterators
14.5Replacing Regular Expressions
14.6RegexFlags
14.7Regex Exceptions
14.8TheRegexECMAScriptGrammar
14.9OtherGrammars
14.10Basic Regex Signatures in Detail
15Input/Output Using Stream Classes
15.1Common Background of I/O Streams
15.1.1StreamObjects
15.1.2StreamClasses
15.1.3Global Stream Objects
15.1.4StreamOperators
15.1.5Manipulators
15.1.6ASimpleExample
15.2Fundamental Stream Classes and Objects
15.2.1Classes andClassHierarchy
15.2.2Global Stream Objects
15.2.3HeaderFiles
15.3Standard Stream Operators << and >>
15.3.1Output Operator <<
15.3.2Input Operator >>
15.3.3Input/Output of Special Types
15.4StateofStreams
15.4.1Constants for theStateofStreams
15.4.2Member Functions Accessing the State of Streams
15.4.3Stream State and Boolean Conditions
15.4.4Stream State and Exceptions
15.5Standard Input/Output Functions
15.5.1Member Functions for Input
15.5.2Member Functions for Output
15.5.3ExampleUses
15.5.4sentryObjects
15.6Manipulators
15.6.1Overview of All Manipulators
15.6.2How Manipulators Work
15.6.3User-Defined Manipulators
15.7Formatting
15.7.1FormatFlags
15.7.2Input/Output Format of Boolean Values
15.7.3Field Width, Fill Character, and Adjustment
15.7.4PositiveSignandUppercaseLetters
15.7.5NumericBase
15.7.6Floating-Point Notation
15.7.7General Formatting Definitions
15.8Internationalization
15.9File Access
15.9.1FileStreamClasses
15.9.2Rvalue and Move Semantics for File Streams
15.9.3FileFlags
15.9.4Random Access
15.9.5Using File Descriptors
15.10Stream Classes for Strings
15.10.1StringStreamClasses
15.10.2Move Semantics for String Streams
15.10.3char*StreamClasses
15.11Input/Output Operators for User-Defined Types
15.11.1Implementing Output Operators
15.11.2Implementing Input Operators
15.11.3Input/Output Using Auxiliary Functions
15.11.4User-DefinedFormatFlags
15.11.5Conventions for User-Defined Input/Output Operators
15.12Connecting Input and Output Streams
15.12.1Loose Coupling Using tie()
15.12.2Tight Coupling Using Stream Buffers
15.12.3Redirecting Standard Streams
15.12.4Streams for Reading and Writing
15.13TheStreamBufferClasses
15.13.1The Stream Buffer Interfaces
15.13.2StreamBuffer Iterators
15.13.3User-DefinedStreamBuffers
15.14Performance Issues
15.14.1Synchronization with C’s Standard Streams
15.14.2BufferinginStreamBuffers
15.14.3UsingStreamBuffersDirectly
16Internationalization
16.1Character Encodings and Character Sets
16.1.1Multibyte and Wide-Character Text
16.1.2DifferentCharacterSets
16.1.3Dealing with Character Sets in C++
16.1.4CharacterTraits
16.1.5Internationalization of Special Characters
16.2TheConceptofLocales
16.2.1UsingLocales
16.2.2Locale Facets
16.3Locales inDetail
16.4Facets in Detail
16.4.1Numeric Formatting
16.4.2Monetary Formatting
16.4.3Time and Date Formatting
16.4.4Character Classification and Conversion
16.4.5String Collation
16.4.6Internationalized Messages
17Numerics
17.1Random Numbers and Distributions
17.1.1AFirstExample
17.1.2Engines
17.1.3Engines in Detail
17.1.4Distributions
17.1.5Distributions in Detail
17.2ComplexNumbers
17.2.1Class complex<> inGeneral
17.2.2Examples Using Class complex<>
17.2.3Operations for Complex Numbers
17.2.4Class complex<> inDetail
17.3Global Numeric Functions
17.4Valarrays
18Concurrency
18.1The High-Level Interface: async() and Futures
18.1.1A First Example Using async() and Futures
18.1.2An Example of Waiting for Two Tasks
18.1.3Shared Futures
18.2The Low-Level Interface: Threads and Promises
18.2.1Class std::thread
18.2.2Promises
18.2.3Class packaged_task<>
18.3Starting a Thread in Detail
18.3.1async() inDetail
18.3.2Futures in Detail
18.3.3Shared Futures in Detail
18.3.4Class std::promise inDetail
18.3.5Class std::packaged_task inDetail
18.3.6Class std::thread inDetail
18.3.7Namespace this_thread
18.4Synchronizing Threads, or the Problem of Concurrency
18.4.1BewareofConcurrency!
18.4.2The Reason for the Problem of Concurrent Data Access
18.4.3What Exactly Can Go Wrong (the Extent of theProblem)
18.4.4The Features to Solve the Problems
18.5Mutexes andLocks
18.5.1UsingMutexes andLocks
18.5.2Mutexes andLocks inDetail
18.5.3Calling Once for Multiple Threads
18.6Condition Variables
18.6.1Purpose of Condition Variables
18.6.2A First Complete Example for Condition Variables
18.6.3Using Condition Variables to Implement a Queue forMultiple Threads
18.6.4Condition Variables in Detail
18.7Atomics
18.7.1ExampleofUsingAtomics
18.7.2Atomics and Their High-Level Interface in Detail
18.7.3The C-Style Interface of Atomics
18.7.4TheLow-Level InterfaceofAtomics
19Allocators
19.1Using Allocators as an Application Programmer
19.2AUser-DefinedAllocator
19.3UsingAllocators as aLibraryProgrammer
Bibliography
Newsgroups and Forums
Books and Web Sites
Index