C++
The Comprehensive Guide
Información
- Editorial: SAP PRESS
- Autores: Torsten T. Will
- Año: 2025
- Edición: 1
- Páginas: 1089
- Idiomas: Inglés
Descripción
If you need to know C++, look no further! This comprehensive guide has everything you need to master the modern C++23 language, from syntax fundamentals to advanced development concepts. Follow practical code examples as you learn object-oriented programming, work with standard library containers, program concurrent applications, and more. Don’t just learn how to code—learn how to code better with expert tips and guidance on the rules of compact, secure, and efficient code.
- Your all in one guide to modern C++
- Work with the C++ language, from basic syntax and functions to more advanced features such as pointers and macros
- Learn to use the standard library and containers
Aspectos Destacados
- Language basics
- Statements and expressions
- Structures and classes
- Object-oriented programming
- Containers
- Threading
- Error handling
- Testing
- Pointers
- Interface to C
- Templates
- Best practices
Aprenderás sobre
- Basic to Advanced Programming:
Master C++ programming from the ground up. Learn how to code with building blocks such as comments, variables, and functions, and then walk through object-oriented programming. Graduate to advanced concepts, including pointers and templates.
- The Standard Library:
Dive into the C++ standard library, including an in-depth guide to containers: what they can do, what they can’t do, and how to choose the right one for your scenario. Work with streams and files, explore unique syntax, and implement concurrency using threads.
- Good Coding Practices:
Write effective, sustainable code. Dedicated chapters provide guidelines, techniques, and tips for good coding. Put theory into practice with numerous sample programs that you can download to help jump-start your own projects.
Tabla de Contenidos
- 1 C++: The Comprehensive Guide
- 1.1 New and Modern
- 1.2 “Dan” Chapters
- 1.3 Presentation in This Book
- 1.4 Formatting Used
- 1.5 Let’s Talk Lingo
- 2 Programming in C++
- 2.1 Compiling
- 2.2 Translation Phases
- 2.3 Current Compilers
- 2.3.1 Gnu C++
- 2.3.2 Clang++ from LLVM
- 2.3.3 Microsoft Visual C++
- 2.3.4 Compiler in the Container
- 2.4 Development Environments
- 2.5 The Command Line under Ubuntu
- 2.5.1 Create a Program
- 2.5.2 Automate with Makefile
- 2.6 The Visual Studio Code IDE under Windows
- 2.7 Speed Up the Sample Program
- 4 The Basic Building Blocks of C++
- 4.1 A Quick Overview
- 4.1.1 Comments
- 4.1.2 The “include” Directive
- 4.1.3 The Standard Library
- 4.1.4 The “main()” Function
- 4.1.5 Types
- 4.1.6 Variables
- 4.1.7 Initialization
- 4.1.8 Output on the Console
- 4.1.9 Statements
- 4.2 A Detailed Walkthrough
- 4.2.1 Spaces, Identifiers, and Tokens
- 4.2.2 Comments
- 4.2.3 Functions and Arguments
- 4.2.4 Side Effect Operators
- 4.2.5 The “main” Function
- 4.2.6 Statements
- 4.2.7 Expressions
- 4.2.8 Allocations
- 4.2.9 Types
- 4.2.10 Variables: Declaration, Definition, and Initialization
- 4.2.11 Initialize with “auto”
- 4.2.12 Details on the Include Directive
- 4.2.13 Modules
- 4.2.14 Input and Output
- 4.2.15 The “std” Namespace
- 4.3 Operators
- 4.3.1 Operators and Operands
- 4.3.2 Overview of Operators
- 4.3.3 Arithmetic Operators
- 4.3.4 Bit-by-Bit Arithmetic
- 4.3.5 Composite Assignment
- 4.3.6 Post- and Preincrement and Post- and Predecrement
- 4.3.7 Relational Operators
- 4.3.8 Logical Operators
- 4.3.9 Pointer and Dereference Operators
- 4.3.10 Special Operators
- 4.3.11 Function-Like Operators
- 4.3.12 Operator Sequence
- 4.4 Built-In Data Types
- 4.4.1 Overview
- 4.4.2 Initialize Built-In Data Types
- 4.4.3 Integers
- 4.4.4 Floating-Point Numbers
- 4.4.5 Truth Values
- 4.4.6 Character Types
- 4.4.7 Complex Numbers
- 4.5 Undefined Behavior
- 5 Good Code, 1st Dan: Writing Readable Code
- 5.1 Comments
- 5.2 Documentation
- 5.3 Indentations and Line Length
- 5.4 Lines per Function and File
- 5.5 Brackets and Spaces
- 5.6 Names
- 6 Higher Data Types
- 6.1 The String Type “string”
- 6.1.1 Initialization
- 6.1.2 Functions and Methods
- 6.1.3 Other String Types
- 6.1.4 For Viewing Only: “string_view”
- 6.2 Streams
- 6.2.1 Input and Output Operators
- 6.2.2 “getline”
- 6.2.3 Files for Input and Output
- 6.2.4 Manipulators
- 6.2.5 The “endl” Manipulator
- 6.3 Container and Pointer
- 6.3.1 Container
- 6.3.2 Parameterized Types
- 6.4 The Simple Sequence Containers
- 6.4.1 “array”
- 6.4.2 “vector”
- 6.5 Algorithms
- 6.6 Pointers and C-Arrays
- 6.6.1 Pointer Types
- 6.6.2 C-Arrays
- 7 Functions
- 7.1 Declaration and Definition of a Function
- 7.2 Function Type
- 7.3 Using Functions
- 7.4 Defining a Function
- 7.5 More about Parameters
- 7.5.1 Call-by-Value
- 7.5.2 Call-by-Reference
- 7.5.3 Constant References
- 7.5.4 Call as Value, Reference, or Constant Reference?
- 7.6 Functional Body
- 7.7 Converting Parameters
- 7.8 Overloading Functions
- 7.9 Default Parameter
- 7.10 Arbitrary Number of Arguments
- 7.11 Alternative Notation for Function Declaration
- 7.12 Specialties
- 7.12.1 “noexcept”
- 7.12.2 Inline Functions
- 7.12.3 “constexpr”
- 7.12.4 Deleted Functions
- 7.12.5 Specialties in Class Methods
- 8 Statements in Detail
- 8.1 The Statement Block
- 8.1.1 Standalone Blocks and Variable Scope
- 8.2 The Empty Statement
- 8.3 Declaration Statement
- 8.4 The Expression Statement
- 8.5 The “if” Statement
- 8.5.1 “if” with Initializer
- 8.5.2 Compile-Time “if”
- 8.6 The “while” Loop
- 8.7 The “do-while” Loop
- 8.8 The “for” Loop
- 8.9 The Range-Based “for” Loop
- 8.10 The “switch” Statement
- 8.11 The “break” Statement
- 8.12 The “continue” Statement
- 8.13 The “return” Statement
- 8.14 The “goto” Statement
- 8.15 The “try-catch” Block and “throw”
- 8.16 Summary
- 9 Expressions in Detail
- 9.1 Calculations and Side Effects
- 9.2 Types of Expressions
- 9.3 Literals
- 9.4 Identifiers
- 9.5 Parentheses
- 9.6 Function Call and Index Access
- 9.7 Assignment
- 9.8 Type Casting
- 10 Error Handling
- 10.1 Error Handling with Error Codes
- 10.2 What Is an Exception?
- 10.2.1 Throwing and Handling Exceptions
- 10.2.2 Unwinding the Call Stack
- 10.3 Minor Error Handling
- 10.4 Throwing the Exception Again: “rethrow”
- 10.5 The Order in “catch”
- 10.5.1 No “finally”
- 10.5.2 Standard Library Exceptions
- 10.6 Types for Exceptions
- 10.7 When an Exception Falls Out of “main”
- 11 Good Code, 2nd Dan: Modularization
- 11.1 Program, Library, Object File
- 11.2 Modules
- 11.3 Separating Functionalities
- 11.4 A Modular Example Project
- 11.4.1 Namespaces
- 11.4.2 Implementation
- 11.4.3 Using the Library
- PART II Object-Oriented Programming and More
- 12 From Structure to Class
- 12.1 Initialization
- 12.2 Returning Custom Types
- 12.3 Methods Instead of Functions
- 12.4 The Better “print”
- 12.5 An Output Like Any Other
- 12.6 Defining Methods Inline
- 12.7 Separate Implementation and Definition
- 12.8 Initialization via Constructor
- 12.8.1 Member Default Values in Declaration
- 12.8.2 Constructor Delegation
- 12.8.3 Default Values for Constructor Parameters
- 12.8.4 Do Not Call the “init” Method in the Constructor
- 12.8.5 Exceptions in the Constructor
- 12.9 Struct or Class?
- 12.9.1 Encapsulation
- 12.9.2 “public” and “private”, Struct and Class
- 12.9.3 Data with “struct”, Behavior with “class”
- 12.9.4 Initialization of Types with Private Data
- 12.10 Interim Recap
- 12.11 Using Custom Data Types
- 12.11.1 Using Classes as Values
- 12.11.2 Using Constructors
- 12.11.3 Type Conversions
- 12.11.4 Encapsulate and Decapsulate
- 12.11.5 Give Types a Local Name
- 12.12 Type Inference with “auto”
- 12.13 Custom Classes in Standard Containers
- 12.13.1 Three-Way Comparison: The Spaceship Operator
- 13 Namespaces and Qualifiers
- 13.1 The “std” Namespace
- 13.2 Anonymous Namespace
- 13.3 “static” Makes Local
- 13.4 “static” Likes to Share
- 13.5 Remote Initialization or “static inline” Data Fields
- 13.6 Guaranteed to Be Initialized at Compile Time with “constinit”
- 13.7 “static” Makes Permanent
- 13.8 “inline namespace”
- 13.9 Interim Recap
- 13.10 “const”
- 13.10.1 Const Parameters
- 13.10.2 Const Methods
- 13.10.3 “const” Variables
- 13.10.4 Const Returns
- 13.10.5 “const” Together with “static”
- 13.10.6 Even More Constant with “constexpr”
- 13.10.7 “if constexpr” for Compile-Time Decisions
- 13.10.8 C++20: “consteval”
- 13.10.9 “if consteval”
- 13.10.10 Un-“const” with “mutable”
- 13.10.11 Const-Correctness
- 13.10.12 Summary
- 13.11 Volatile with “volatile”
- 14 Good Code, 3rd Dan: Testing
- 14.1 Types of Tests
- 14.1.1 Refactoring
- 14.1.2 Unit Tests
- 14.1.3 Social or Solitary
- 14.1.4 Doppelgangers
- 14.1.5 Suites
- 14.2 Frameworks
- 14.2.1 Arrange, Act, Assert
- 14.2.2 Frameworks to Choose From
- 14.3 Boost.Test
- 14.4 Helper Macros for Assertions
- 14.5 An Example Project with Unit Tests
- 14.5.1 Private and Public Testing
- 14.5.2 An Automatic Test Module
- 14.5.3 Compile Test
- 14.5.4 Assemble the Test Suite Yourself
- 14.5.5 Testing Private Members
- 14.5.6 Parameterized Tests
- 15 Inheritance
- 15.1 Relationships
- 15.1.1 Has-a Composition
- 15.1.2 Has-a Aggregation
- 15.1.3 Is-a Inheritance
- 15.1.4 Instance-of versus Is-a Relationship
- 15.2 Inheritance in C++
- 15.3 Has-a versus Is-a
- 15.4 Finding Commonalities
- 15.5 Derived Types Extend
- 15.6 Overriding Methods
- 15.7 How Methods Work
- 15.8 Virtual Methods
- 15.9 Constructors in Class Hierarchies
- 15.10 Type Conversion in Class Hierarchies
- 15.10.1 Converting Up the Inheritance Hierarchy
- 15.10.2 Downcasting the Inheritance Hierarchy
- 15.10.3 References Also Retain Type Information
- 15.11 When to Use Virtual?
- 15.12 Other Designs for Extensibility
- 16 The Lifecycle of Classes
- 16.1 Creation and Destruction
- 16.2 Temporary: Short-Lived Values
- 16.3 The Destructor to the Constructor
- 16.3.1 No Destructor Needed
- 16.3.2 Resources in the Destructor
- 16.4 Yoda Condition
- 16.5 Construction, Destruction, and Exceptions
- 16.6 Copy
- 16.7 Assignment Operator
- 16.8 Removing Methods
- 16.9 Move Operations
- 16.9.1 What the Compiler Generates
- 16.10 Operators
- 16.11 Custom Operators in a Data Type
- 16.12 Special Class Forms
- 16.12.1 Abstract Classes and Methods
- 16.12.2 Enumeration Classes
- 17 Good Code, 4th Dan: Security, Quality, and Sustainability
- 17.1 The Rule of Zero
- 17.1.1 The Big Five
- 17.1.2 Helper Construct by Prohibition
- 17.1.3 The Rule of Zero and Its Application
- 17.1.4 Exceptions to the Rule of Zero
- 17.1.5 Rule of Zero, Rule of Three, Rule of Five, Rule of Four and a Half
- 17.2 Resource Acquisition Is Initialization
- 17.2.1 An Example with C
- 17.2.2 Owning Raw Pointers
- 17.2.3 From C to C++
- 17.2.4 It Doesn't Always Have to Be an Exception
- 17.2.5 Multiple Constructors
- 17.2.6 Multiphase Initialization
- 17.2.7 Define Where It Is Needed
- 17.2.8 “new” without Exceptions
- 18 Specials for Classes
- 18.1 Allowed to See Everything: “friend” Classes
- 18.1.1 “friend class” Example
- 18.2 Nonpublic Inheritance
- 18.2.1 Impact on the Outside World
- 18.2.2 Nonpublic Inheritance in Practice
- 18.3 Signature Classes as Interfaces
- 18.4 Multiple Inheritance
- 18.4.1 Multiple Inheritance in Practice
- 18.4.2 Caution with Pointer Type Conversions
- 18.4.3 The Observer Pattern as a Practical Example
- 18.5 Diamond-Shaped Multiple Inheritance: “virtual” for Class Hierarchies
- 18.6 Literal Data Types: “constexpr” for Constructors
- 19 Good Code, 5th Dan: Classical Object-Oriented Design
- 19.1 Objects in C++
- 19.2 Object-Oriented Design
- 19.2.1 SOLID
- 19.2.2 Don't Be STUPID
- 20 Pointers
- 20.1 Addresses
- 20.2 Pointer
- 20.3 Dangers of Aliasing
- 20.4 Heap Memory and Stack Memory
- 20.4.1 The Stack
- 20.4.2 The Heap
- 20.5 Smart Pointers
- 20.5.1 “unique_ptr”
- 20.5.2 “shared_ptr”
- 20.6 Raw Pointers
- 20.7 C-Arrays
- 20.7.1 Calculating with Pointers
- 20.7.2 Decay of C-Arrays
- 20.7.3 Dynamic C-Arrays
- 20.7.4 String Literals
- 20.8 Iterators
- 20.9 Pointers as Iterators
- 20.10 Pointers in Containers
- 20.11 The Exception: When Cleanup Is Not Necessary
- 21 Macros
- 21.1 The Preprocessor
- 21.2 Beware of Missing Parenthesis
- 21.3 Feature Macros
- 21.4 Information about the Source Code
- 21.5 Warning about Multiple Executions
- 21.6 Type Variability of Macros
- 21.7 Summary
- 22 Interface to C
- 22.1 Working with Libraries
- 22.2 C Header
- 22.3 C Resources
- 22.4 “void” Pointers
- 22.5 Reading Data
- 22.6 The Main Program
- 22.7 Summary
- 23 Templates
- 23.1 Function Templates
- 23.1.1 Overloading
- 23.1.2 A Type as Parameter
- 23.1.3 Function Body of a Function Template
- 23.1.4 Values as Template Parameters
- 23.1.5 Many Functions
- 23.1.6 Parameters with Extras
- 23.1.7 Method Templates are Just Function Templates
- 23.2 Function Templates in the Standard Library
- 23.2.1 Ranges instead of Containers as Template Parameters
- 23.2.2 Example: Information about Numbers
- 23.3 A Class as a Function
- 23.3.1 Values for a “Function” Parameter
- 23.3.2 C Function Pointer
- 23.3.3 The Somewhat Different Function
- 23.3.4 Practical Functors
- 23.3.5 Algorithms with Functors
- 23.3.6 Anonymous Functions: a.k.a. Lambda Expressions
- 23.3.7 Template Functions without “template”, but with “auto”
- 23.4 C++ Concepts
- 23.4.1 How to Read Concepts
- 23.4.2 How to Use Concepts
- 23.4.3 How to Write Concepts
- 23.4.4 Semantic Constraints
- 23.4.5 Interim Recap
- 23.5 Template Classes
- 23.5.1 Implementing Class Templates
- 23.5.2 Implementing Methods of Class Templates
- 23.5.3 Creating Objects from Class Templates
- 23.5.4 Class Templates with Multiple Formal Data Types
- 23.5.5 Class Templates with Nontype Parameters
- 23.5.6 Class Templates with Defaults
- 23.5.7 Specializing Class Templates
- 23.6 Templates with Variable Argument Count
- 23.6.1 “sizeof ...” Operator
- 23.6.2 Convert Parameter Pack to Tuple
- 23.7 Custom Literals
- 23.7.1 What Are Literals?
- 23.7.2 Naming Rules
- 23.7.3 Literal Processing Phases
- 23.7.4 Overloading Variants
- 23.7.5 User-Defined Literal Using Template
- 23.7.6 Raw or Cooked
- 23.7.7 Automatically Merged
- 23.7.8 Unicode Literals
- PART IV The Standard Library
- 24 Containers
- 24.1 Basics
- 24.1.1 Recurring
- 24.1.2 Abstract
- 24.1.3 Operations
- 24.1.4 Complexity
- 24.1.5 Containers and Their Iterators
- 24.1.6 Ranges Simplify Iterators
- 24.1.7 Ranges, Views, Concepts, Adapters, Generators, and Algorithms
- 24.1.8 Algorithms
- 24.2 Iterator Basics
- 24.2.1 Iterators from Containers
- 24.2.2 More Functionality with Iterators
- 24.3 Allocators: Memory Issues
- 24.4 Container Commonalities
- 24.5 An Overview of the Standard Container Classes
- 24.5.1 Type Aliases of Containers
- 24.6 The Sequential Container Classes
- 24.6.1 Commonalities and Differences
- 24.6.2 Methods of Sequence Containers
- 24.6.3 “vector”
- 24.6.4 “array”
- 24.6.5 “deque”
- 24.6.6 “list”
- 24.6.7 “forward_list”
- 24.7 Associative and Ordered
- 24.7.1 Commonalities and Differences
- 24.7.2 Methods of Ordered Associative Containers
- 24.7.3 “set”
- 24.7.4 “map”
- 24.7.5 “multiset”
- 24.7.6 “multimap”
- 24.8 Only Associative and Not Guaranteed
- 24.8.1 Hash Tables
- 24.8.2 Commonalities and Differences
- 24.8.3 Methods of Unordered Associative Containers
- 24.8.4 “unordered_set”
- 24.8.5 “unordered_map”
- 24.8.6 “unordered_multiset”
- 24.8.7 “unordered_multimap”
- 24.9 Container Adapters
- 24.10 Special Cases: “string”, “basic_string”, and “vector<char>”
- 24.11 Special Cases: “vector<bool>”, “array<bool,n>”, and “bitset<n>”
- 24.11.1 Dynamic and Compact: “vector<bool>”
- 24.11.2 Static: “array<bool,n>” and “bitset<n>”
- 24.12 Special Case: Value Array with “valarray<>”
- 24.12.1 Element Properties
- 24.12.2 Initialize
- 24.12.3 Assignment
- 24.12.4 Insert and Delete
- 24.12.5 Accessing
- 24.12.6 Specialty: Manipulate All Data
- 24.12.7 Specialty: Slicing and Masking
- 25 Container Support
- 25.1 Algorithms
- 25.2 Iterators and Ranges
- 25.3 Iterator Adapter
- 25.4 Algorithms of the Standard Library
- 25.5 Parallel Execution
- 25.6 Lists of Algorithm Functions and Range Adapters
- 25.6.1 Range Adapters and Views
- 25.6.2 Ranges as Parameters (and More)
- 25.6.3 List of Nonmodifying Algorithms
- 25.6.4 Inherently Modifying Algorithms
- 25.6.5 Algorithms for Partitions
- 25.6.6 Algorithms for Sorting and Fast Searching in Sorted Ranges
- 25.6.7 Set Algorithms Represented by a Sorted Range
- 25.6.8 Heap Algorithms
- 25.6.9 Minimum and Maximum
- 25.6.10 Various Algorithms
- 25.7 Element-Linking Algorithms from “<numeric>” and “<ranges>”
- 25.8 Copy instead of Assignment: Values in Uninitialized Memory Areas
- 25.9 Custom Algorithms
- 25.10 Writing Custom Views and Range Adapters
- 26 Good Code, 6th Dan: The Right Container for Each Task
- 26.1 All Containers Arranged by Aspects
- 26.1.1 When Is a “vector” Not the Best Choice?
- 26.1.2 Always Sorted: “set”, “map”, “multiset”, and “multimap”
- 26.1.3 In Memory Contiguously: “vector”, “array”
- 26.1.4 Cheap Insertion: “list”
- 26.1.5 Low Memory Overhead: “vector”, “array”
- 26.1.6 Size Dynamic: All Except “array”
- 26.2 Recipes for Containers
- 26.2.1 Two Phases? “vector” as a Good “set” Replacement
- 26.2.2 Output the Contents of a Container to a Stream
- 26.2.3 So “array” Is Not That Static
- 26.3 Implementing Algorithms That Are Specialized Depending on the Container
- 27 Streams, Files, and Formatting
- 27.1 Input and Output Concept with Streams
- 27.2 Global, Predefined Standard Streams
- 27.2.1 Stream Operators << and >>
- 27.3 Methods for Stream Input and Output
- 27.3.1 Methods for Unformatted Output
- 27.3.2 Methods for Unformatted Input
- 27.4 Error Handling and Stream States
- 27.4.1 Methods for Handling Stream Errors
- 27.5 Manipulating and Formatting Streams
- 27.5.1 Manipulators
- 27.5.2 Creating Custom Manipulators without Arguments
- 27.5.3 Creating Custom Manipulators with Arguments
- 27.5.4 Directly Change Format Flags
- 27.6 Streams for File Input and Output
- 27.6.1 The “ifstream”, “ofstream”, and “fstream” Streams
- 27.6.2 Connecting to a File
- 27.6.3 Reading and Writing
- 27.6.4 Random Access
- 27.6.5 Synchronized Streams for Threads
- 27.7 Streams for Strings
- 27.7.1 Difference from “to_string”
- 27.7.2 “to_chars” and “format” Are More Flexible than “to_string”
- 27.7.3 Reading from a String
- 27.8 Stream Buffers
- 27.8.1 Access to the Stream Buffer of “iostream” Objects
- 27.8.2 “filebuf”
- 27.8.3 “stringbuf”
- 27.9 “filesystem”
- 27.10 Formatting
- 27.10.1 Simple Formatting
- 27.10.2 Formatting Custom Types
- 28 Standard Library: Extras
- 28.1 “pair” and “tuple”
- 28.1.1 Returning Multiple Values
- 28.2 Regular Expressions
- 28.2.1 Matching and Searching
- 28.2.2 The Result and Parts of It
- 28.2.3 Found Replacement
- 28.2.4 Rich in Variants
- 28.2.5 Iterators
- 28.2.6 Matches
- 28.2.7 Options
- 28.2.8 Speed
- 28.2.9 Standard Syntax, Slightly Shortened
- 28.2.10 Notes on Regular Expressions in C++
- 28.3 Randomness
- 28.3.1 Rolling a Die
- 28.3.2 True Randomness
- 28.3.3 Other Generators
- 28.3.4 Distributions
- 28.4 Mathematical
- 28.4.1 Fraction and Time: “<ratio>” and “<chrono>”
- 28.4.2 Predefined Suffixes for User-Defined Literals
- 28.5 System Error Handling with “system_error”
- 28.5.1 Overview
- 28.5.2 Principles
- 28.5.3 “error_code” and “error_condition”
- 28.5.4 Error Categories
- 28.5.5 Custom Error Codes
- 28.5.6 “system_error” Exception
- 28.6 Runtime Type Information: “<typeinfo>” and “<typeindex>”
- 28.7 Helper Classes around Functors: “<functional>”
- 28.7.1 Function Objects
- 28.7.2 Function Generators
- 28.8 “optional” for a Single Value or No Value
- 28.9 “variant” for One of Several Types
- 28.10 “any” Holds Any Type
- 28.11 Special Mathematical Functions
- 28.12 Fast Conversion with “<charconv>”
- 29 Threads: Programming with Concurrency
- 29.1 C++ Threading Basics
- 29.1.1 Starting Pure Threads
- 29.1.2 Terminating a Thread Prematurely
- 29.1.3 Waiting for a Thread
- 29.1.4 Consider Exceptions in the Starting Thread
- 29.1.5 Passing Parameters to a Thread Function
- 29.1.6 Moving a Thread
- 29.1.7 How Many Threads to Start?
- 29.1.8 Which Thread Am I?
- 29.2 Shared Data
- 29.2.1 Data Races
- 29.2.2 Latch
- 29.2.3 Barriers
- 29.2.4 Mutexes
- 29.2.5 Interface Design for Multithreading
- 29.2.6 Locks Can Lead to Deadlock
- 29.2.7 More Flexible Locking with “unique_lock”
- 29.3 Other Synchronization Options
- 29.3.1 Call Only Once with “once_flag” and “call_once”
- 29.3.2 Locking with “recursive_mutex”
- 29.4 In Its Own Storage with “thread_local”
- 29.5 Waiting for Events with “condition_variable”
- 29.5.1 “notify_all”
- 29.5.2 Synchronize Output
- 29.6 Waiting Once with “future”
- 29.6.1 Launch Policies
- 29.6.2 Wait Until a Certain Time
- 29.6.3 Exception Handling with “future”
- 29.6.4 “promise”
- 29.7 Atomics
- 29.7.1 Overview of the Operations
- 29.7.2 Memory Order
- 29.7.3 Example
- 29.8 Coroutines
- 29.8.1 Coroutines in the Compiler
- 29.8.2 Generator
- 29.8.3 Coroutines with “promise_type”
- 29.9 Summary
- 29.9.1 “<thread>” Header
- 29.9.2 “<latch>” and “<barrier>” Headers
- 29.9.3 “<mutex>” and “<shared mutex>” Headers
- 29.9.4 “<condition variable>” Header
- 29.9.5 “<future>” Header
- 29.9.6 “<atomic>” Header
- 29.9.7 “<coroutine>” Header
- 30 Good Code, 7th Dan: Guidelines
- 30.1 Guideline Support Library
- 30.2 C++ Core Guidelines
- 30.2.1 Motivation
- 30.2.2 Type Safety
- 30.2.3 Use RAII
- 30.2.4 Class Hierarchies
- 30.2.5 Generic Programming
- 30.2.6 Do Not Be Confused by Anachronisms
- Appendices
- A Cheat Sheet
- B The Author
Descargo de responsabilidad
SAP, otros productos SAP y servicios mencionados aquí así como sus respectivos logos son marca registrada de SAP SE (o una compañía afiliada de SAP) en Alemania y otros países. Nuestra compañía no está afiliada con SAP SE ni con ninguna de sus compañías afiliadas incluyendo pero no limitada a: Sybase, Business Objects, Hybris, Ariba y SuccessFactors. Todos los otros nombres, marcas, logos, etc. son marcas o servicios registrados de sus respectivos propietarios.