C++20. Get the Details

My book C++20 is both: a tutorial and a reference for the C++20 standard. It teaches you C++20 and provides you with the

169 77 11MB

English Pages 600 Year 2021

Report DMCA / Copyright

DOWNLOAD FILE

C++20. Get the Details

  • Commentary
  • Update 2021-08-28

Table of contents :
Reader Testimonials
Introduction
Conventions
Special Fonts
Special Boxes
Source Code
Compilation of the Programs
How should you read the Book?
Personal Notes
Acknowledgments
About Me

About C++

1. Historical Context
1.1 C++98
1.2 C++03
1.3 TR1
1.4 C++11
1.5 C++14
1.6 C++17
2. Standardization
2.1 Stage 3
2.2 Stage 2
2.3 Stage 1

A Quick Overview of C++20

3. C++20
3.1 The Big Four
3.1.1 Concepts
3.1.2 Modules
3.1.3 The Ranges Library
3.1.4 Coroutines
3.2 Core Language
3.2.1 Three-Way Comparison Operator
3.2.2 Designated Initialization
3.2.3 consteval and constinit
3.2.4 Template Improvements
3.2.5 Lambda Improvements
3.2.6 New Attributes
3.3 The Standard Library
3.3.1 std::span
3.3.2 Container Improvements
3.3.3 Arithmetic Utilities
3.3.4 Formatting Library
3.3.5 Calendar and Time Zones
3.4 Concurrency
3.4.1 Atomics
3.4.2 Semaphores
3.4.3 Latches and Barriers
3.4.4 Cooperative Interruption
3.4.5 std::jthread
3.4.6 Synchronized Outputstreams

The Details

4. Core Language
4.1 Concepts
4.1.1 Two Wrong Approaches
4.1.2 Advantages of Concepts
4.1.3 The long, long History
4.1.4 Use of Concepts
4.1.5 Constrained and Unconstrained Placeholders
4.1.6 Abbreviated Function Templates
4.1.7 Predefined Concepts
4.1.8 Define Concepts
4.1.9 Requires Expressions
4.1.10 User-Defined Concepts
4.2 Modules
4.2.1 Why do we need Modules?
4.2.2 Advantages
4.2.3 A First Example
4.2.4 Compiler Support
4.2.5 Export
4.2.6 Guidelines for a Module Structure
4.2.7 Module Interface Unit and Module Implementation Unit
4.2.8 Private Module Fragment
4.2.9 Submodules and Module Partitions
4.2.10 Templates in Modules
4.2.11 Module Linkage
4.2.12 Header Units
4.3 Equality Comparison and Three-Way Comparison
4.3.1 Comparison before C++20
4.3.2 Comparison since C++20
4.3.3 Comparison Categories
4.3.4 Compiler-Generated Equality and Spaceship Operator
4.3.5 Rewriting Expressions
4.3.6 User-Defined and Auto-Generated Comparison Operators
4.4 Designated Initialization
4.4.1 Aggregate Initialization
4.4.2 Named Initialization of Class Members
4.5 consteval and constinit
4.5.1 consteval
4.5.2 constinit
4.5.3 Comparison of const, constexpr, consteval, and constinit
4.5.4 Solving the Static Initialization Order Fiasco
4.6 Template Improvements
4.6.1 Conditionally Explicit Constructor
4.6.2 Non-Type Template Parameters (NTTP)
4.7 Lambda Improvements
4.7.1 Template Parameter for Lambdas
4.7.2 Detection of the Implicit Copy of the this Pointer
4.7.3 Lambdas in an Unevaluated Context and Stateless Lambdas can be Default-Constructed and Copy-Assigned
4.7.4 Pack Expansion in Init-Capture
4.8 New Attributes
4.8.1 [[nodiscard("reason")]]
4.8.2 [[likely]] and [[unlikely]]
4.8.3 [[no_unique_address]]
4.9 Further Improvements
4.9.1 volatile
4.9.2 Range-based for loop with Initializers
4.9.3 Virtual constexpr function
4.9.4 The new Character Type of UTF-8 Strings: char8_t
4.9.5 using enum in Local Scopes
4.9.6 Default Member Initializers for Bit Fields
5. The Standard Library
5.1 The Ranges Library
5.1.1 Ranges
5.1.2 Views
5.1.3 Direct on the Container
5.1.4 Function Composition
5.1.5 Lazy Evaluation
5.1.6 Define a View
5.1.7 A Flavor of Python
5.2 std::span
5.2.1 Static versus Dynamic Extent
5.2.2 Creation
5.2.3 Automatically Deduces the Size of a Contiguous Sequence of Objects
5.2.4 Modifying the Referenced Objects
5.2.5 Addressing std::span Elements
5.2.6 A Constant Range of Modifiable Elements
5.2.7 Dangers of std::span
5.3 Container and Algorithm Improvements
5.3.1 constexpr Containers and Algorithms
5.3.2 std::array
5.3.3 Consistent Container Erasure
5.3.4 contains for Associative Containers
5.3.5 Shift the Content of a Container
5.3.6 String prefix and suffix checking
5.4 Arithmetic Utilities
5.4.1 Safe Comparison of Integers
5.4.2 Mathematical Constants
5.4.3 Midpoint and Linear Interpolation
5.4.4 Bit Manipulation
5.5 Formatting Library
5.5.1 Format String
5.5.2 User-Defined Types
5.6 Calendar and Time Zones
5.6.1 Basic Chrono Terminology
5.6.2 Basic Types and Literals
5.6.3 Time of day
5.6.4 Calendar Dates
5.6.5 Time Zones
5.6.6 Chrono I/O
5.7 Further Improvements
5.7.1 std::bind_front
5.7.2 std::is_constant_evaluated
5.7.3 std::source_location
5.7.4 std::to_address
6. Concurrency
6.1 Coroutines
6.1.1 A Generator Function
6.1.2 Characteristics
6.1.3 The Framework
6.1.4 Awaitables and Awaiters
6.1.5 The Workflows
6.1.6 co_return
6.1.7 co_yield
6.1.8 co_await
6.2 Atomics
6.2.1 std::atomic_ref
6.2.2 Atomic Smart Pointer
6.2.3 std::atomic_flag Extensions
6.2.4 std::atomic Extensions
6.3 Semaphores
6.4 Latches and Barriers
6.4.1 std::latch
6.4.2 std::barrier
6.5 Cooperative Interruption
6.5.1 std::stop_source
6.5.2 std::stop_token
6.5.3 std::stop_callback
6.5.4 A General Mechanism to Send Signals
6.5.5 Joining Threads
6.5.6 New wait Overloads for the condition_variable_any
6.6 std::jthread
6.6.1 Automatically Joining
6.6.2 Cooperative Interruption of a std::jthread
6.7 Synchronized Output Streams
7. Case Studies
7.1 Fast Synchronization of Threads
7.1.1 Condition Variables
7.1.2 std::atomic_flag
7.1.3 std::atomic
7.1.4 Semaphores
7.1.5 All Numbers
7.2 Variations of Futures
7.2.1 A Lazy Future
7.2.2 Execution on Another Thread
7.3 Modification and Generalization of a Generator
7.3.1 Modifications
7.3.2 Generalization
7.4 Various Job Workflows
7.4.1 The Transparent Awaiter Workflow
7.4.2 Automatically Resuming the Awaiter
7.4.3 Automatically Resuming the Awaiter on a Separate Thread

Epilogue
Further Information

8. C++23 and Beyond
8.1 C++23
8.1.1 The Coroutines Library
8.1.2 Modularized Standard Library for Modules
8.1.3 Executors
8.1.4 The Network Library
8.2 C++23 or Later
8.2.1 Contracts
8.2.2 Reflection
8.2.3 Pattern Matching
8.3 Further Information about C++23
9. Feature Testing

Polecaj historie