Preface
- Versions of This Book
- Acknowledgments
About This Book
- What You Should Know Before Reading This Book
- Overall Structure of the Book
- How to Read This Book
- Error Terminology
- The C++17 Standard
- Example Code and Additional Information
- Feedback
- IBasic Language Features
1.Structured Bindings
- 1.1Structured Bindings in Detail
- 1.2Where Structured Bindings Can Be Used
- 1.2.1Structures and Classes
- 1.2.2Raw Arrays
- 1.2.3
std::pair,std::tuple, andstd::array - 1.3Providing a Tuple-Like API for Structured Bindings
- 1.4Afternotes
2.if and switch with Initialization
- 2.1
ifwith Initialization - 2.2
switchwith Initialization - 2.3Afternotes
3.Inline Variables
- 3.1Motivation for Inline Variables
- 3.2Using Inline Variables
- 3.3
constexprNow ImpliesinlineFor Static Members - 3.4Inline Variables and
thread_local - 3.5Afternotes
4.Aggregate Extensions
- 4.1Motivation for Extended Aggregate Initialization
- 4.2Using Extended Aggregate Initialization
- 4.3Definition of Aggregates
- 4.4Backward Incompatibilities
- 4.5Afternotes
5.Mandatory Copy Elision or Passing Unmaterialized Objects
- 5.1Motivation for Mandatory Copy Elision for Temporaries
- 5.2Benefit of Mandatory Copy Elision for Temporaries
- 5.3Clarified Value Categories
- 5.3.1Value Categories
- 5.3.2Value Categories Since C++17
- 5.4Unmaterialized Return Value Passing
- 5.5Afternotes
6.Lambda Extensions
- 6.1
constexprLambdas - 6.1.1Using
constexprLambdas - 6.2Passing Copies of
thisto Lambdas - 6.3Capturing by
constReference - 6.4Afternotes
7.New Attributes and Attribute Features
- 7.1Attribute
[[nodiscard]] - 7.2Attribute
[[maybe_unused]] - 7.3Attribute
[[fallthrough]] - 7.4General Attribute Extensions
- 7.5Afternotes
8.Other Language Features
- 8.1Nested Namespaces
- 8.2Defined Expression Evaluation Order
- 8.3Relaxed Enum Initialization from Integral Values
- 8.4Fixed Direct List Initialization with
auto - 8.5Hexadecimal Floating-Point Literals
- 8.6UTF-8 Character Literals
- 8.7Exception Specifications as Part of the Type
- 8.8Single-Argument
static_assert - 8.9Preprocessor Condition
__has_include - 8.10Afternotes
- IITemplate Features
9.Class Template Argument Deduction
- 9.1Use of Class Template Argument Deduction
- 9.1.1Copying by Default
- 9.1.2Deducing the Type of Lambdas
- 9.1.3No Partial Class Template Argument Deduction
- 9.1.4Class Template Argument Deduction Instead of Convenience Functions
- 9.2Deduction Guides
- 9.2.1Using Deduction Guides to Force Decay
- 9.2.2Non-Template Deduction Guides
- 9.2.3Deduction Guides versus Constructors
- 9.2.4Explicit Deduction Guides
- 9.2.5Deduction Guides for Aggregates
- 9.2.6Standard Deduction Guides
- 9.3Afternotes
10.Compile-Time if
- 10.1Motivation for Compile-Time
if - 10.2Using Compile-Time
if - 10.2.1Caveats for Compile-Time
if - 10.2.2Other Compile-Time
ifExamples - 10.3Compile-Time
ifwith Initialization - 10.4Using Compile-Time
ifOutside Templates - 10.5Afternotes
11.Fold Expressions
- 11.1Motivation for Fold Expressions
- 11.2Using Fold Expressions
- 11.2.1Dealing with Empty Parameter Packs
- 11.2.2Supported Operators
- 11.2.3Using Fold Expressions for Types
- 11.3Afternotes
12.Dealing with String Literals as Template Parameters
- 12.1Using Strings in Templates
- 12.2Afternotes
13.Placeholder Types like auto as Template Parameters
- 13.1Using
autofor Template Parameters - 13.1.1Parameterizing Templates for Characters and Strings
- 13.1.2Defining Metaprogramming Constants
- 13.2Using
autoas Variable Template Parameter - 13.3Using
decltype(auto)as Template Parameter - 13.4Afternotes
14.Extended Using Declarations
- 14.1Using Variadic Using Declarations
- 14.2Variadic Using Declarations for Inheriting Constructors
- 14.3Afternotes
- IIINew Library Components
15.std::optional<>
- 15.1Using
std::optional<> - 15.1.1Optional Return Values
- 15.1.2Optional Arguments and Data Members
- 15.2
std::optional<>Types and Operations - 15.2.1
std::optional<>Types - 15.2.2
std::optional<>Operations - 15.3Special Cases
- 15.3.1Optional of Boolean or Raw Pointer Values
- 15.3.2Optional of Optional
- 15.4Afternotes
16.std::variant<>
- 16.1Motivation for
std::variant<> - 16.2Using
std::variant<> - 16.3
std::variant<>Types and Operations - 16.3.1
std::variant<>Types - 16.3.2
std::variant<>Operations - 16.3.3Visitors
- 16.3.4Valueless by Exception
- 16.4Polymorphism and Heterogeneous Collections with
std::variant - 16.4.1Geometric Objects with
std::variant - 16.4.2Other Heterogeneous Collections with
std::variant - 16.4.3Comparing
variantPolymorphism - 16.5Special Cases with
std::variant<> - 16.5.1Having Both
boolandstd::stringAlternatives - 16.6Afternotes
17.std::any
- 17.1Using
std::any - 17.2
std::anyTypes and Operations - 17.2.1Any Types
- 17.2.2Any Operations
- 17.3Afternotes
18.std::byte
- 18.1Using
std::byte - 18.2
std::byteTypes and Operations - 18.2.1
std::byteTypes - 18.2.2
std::byteOperations - 18.3Afternotes
19.String Views
- 19.1Differences Compared to
std::string - 19.2Using String Views
- 19.3Using String Views as Parameters
- 19.3.1String View Considered Harmful
- 19.4String View Types and Operations
- 19.4.1Concrete String View Types
- 19.4.2String View Operations
- 19.4.3String View Support by Other Types
- 19.5Using String Views in APIs
- 19.5.1Using String Views instead of Strings
- 19.6Afternotes
20.The Filesystem Library
- 20.1Basic Examples
- 20.1.1Print Attributes of a Passed Filesystem Path
- 20.1.2Switch Over Filesystem Types
- 20.1.3Create Different Types of Files {#createfiles.cpp}
- 20.1.4Dealing with Filesystems Using Parallel Algorithms
- 20.2Principles and Terminology
- 20.2.1General Portability Disclaimer
- 20.2.2Namespace
- 20.2.3Paths
- 20.2.4Normalization
- 20.2.5Member Function versus Free-Standing Functions
- 20.2.6Error Handling
- 20.2.7File Types
- 20.3Path Operations
- 20.3.1Path Creation
- 20.3.2Path Inspection
- 20.3.3Path I/O and Conversions
- 20.3.4Conversions Between Native and Generic Format
- 20.3.5Path Modifications
- 20.3.6Path Comparisons
- 20.3.7Other Path Operations
- 20.4Filesystem Operations
- 20.4.1File Attributes
- 20.4.2File Status
- 20.4.3Permissions
- 20.4.4Filesystem Modifications
- 20.4.5Symbolic Links and Filesystem-Dependent Path Conversions
- 20.4.6Other Filesystem Operations
- 20.5Iterating Over Directories
- 20.5.1Directory Entries
- 20.6Afternotes
- IVLibrary Extensions and Modifications
21.Extensions of Type Traits
- 21.1Type Traits Suffix
_v - 21.2New Type Traits
- 21.3Afternotes
22.Parallel STL Algorithms
- 22.1Using Parallel Algorithms
- 22.1.1Using a Parallel
for_each() - 22.1.2Using a Parallel
sort() - 22.2Execution Policies
- 22.3Exception Handling
- 22.4Benefit of Not Using Parallel Algorithms
- 22.5Overview of Parallel Algorithms
- 22.6Motivation for New Algorithms for Parallel Processing
- 22.6.1
reduce() - 22.7Afternotes
23.New STL Algorithms in Detail
- 23.1
std::for_each_n() - 23.2New Numeric STL Algorithms
- 23.2.1
std::reduce() - 23.2.2
std::transform_reduce() - 23.2.3
std::inclusive_scan()andstd::exclusive_scan() - 23.2.4
std::transform_inclusive_scan()andstd::transform_exclusive_scan() - 23.3Afternotes
24.Substring and Subsequence Searchers
- 24.1Using Substring Searchers
- 24.1.1Using Searchers with
search() - 24.1.2Using Searchers Directly
- 24.2Using General Subsequence Searchers
- 24.3Using Searcher Predicates
- 24.4Afternotes
25.Other Utility Functions and Algorithms
- 25.1
size(),empty(), anddata() - 25.1.1Generic
size()Function - 25.1.2Generic
empty()Function - 25.1.3Generic
data()Function - 25.2
as_const() - 25.2.1Capturing by Const Reference
- 25.3
clamp() - 25.4
sample() - 25.5Afternotes
26.Container and String Extensions
- 26.1Node Handles
- 26.1.1Modifying a Key
- 26.1.2Moving Nodes Between Containers
- 26.1.3Merging Containers
- 26.2Emplace Improvements
- 26.2.1Return Type of Emplace Functions
- 26.2.2
try_emplace()andinsert_or_assign()for Maps - 26.3Container Support for Incomplete Types
- 26.4String Improvements
- 26.5Afternotes
27.Multi-Threading and Concurrency
- 27.1Supplementary Mutexes and Locks
- 27.1.1
std::scoped_lock - 27.1.2
std::shared_mutex - 27.2
is_always_lock_freefor Atomics - 27.3Cache Line Sizes
- 27.4Afternotes
28.Other Small Library Features and Modifications
- 28.1
std::uncaught_exceptions() - 28.2Shared Pointer Improvements
- 28.2.1Special handling for Shared Pointers to Raw C Arrays
- 28.2.2
reinterpret_pointer_castfor Shared Pointers - 28.2.3
weak_typefor Shared Pointers - 28.2.4
weak_from_thisfor Shared Pointers - 28.3Numeric Extensions
- 28.3.1Greatest Common Divisor and Least Common Multiple
- 28.3.2Three-Argument Overloads of
std::hypot() - 28.3.3Mathematical Special Functions
- 28.4
chronoExtensions - 28.5
constexprExtensions and Fixes - 28.6
noexceptExtensions and Fixes - 28.7Afternotes
- VExpert Utilities
29.Polymorphic Memory Resources (PMR)
- 29.1Using Standard Memory Resources
- 29.1.1Motivating Example
- 29.1.2Standard Memory Resources
- 29.1.3Standard Memory Resources in Detail
- 29.2Defining Custom Memory Resources
- 29.2.1Equality of Memory Resources
- 29.3Providing Memory Resource Support for Custom Types
- 29.3.1Definition of a PMR Type
- 29.3.2Using a PMR Type
- 29.3.3Dealing with the Different Types
- 29.4Afternotes
30.new and delete with Over-Aligned Data
- 30.1Using
newwith Alignments - 30.1.1Distinct Dynamic/Heap Memory Arenas
- 30.1.2Passing the Alignment with the
newExpression - 30.2Implementing
operator new()for Aligned Memory - 30.2.1Implementing Aligned Allocation Before C++17
- 30.2.2Implementing Type-Specific
operator new() - 30.3Implementing Global
operator new() - 30.3.1Backward Incompatibilities
- 30.4Tracking All
::newCalls - 30.5Afternotes
31.std::to_chars() and std::from_chars()
- 31.1Motivation for Low-Level Conversions between Character Sequences and Numeric Values
- 31.2Example Usage
- 31.2.1
from_chars() - 31.2.2
to_chars() - 31.3Floating-Point Round-Trip Support
- 31.4Afternotes
32.std::launder()
- 32.1Motivation for
std::launder() - 32.2How
launder()Solves the Problem - 32.3Why/When
launder()Does Not Work - 32.4Afternotes
33.Improvements for Implementing Generic Code
- 33.1
std::invoke<>() - 33.2
std::bool_constant<> - 33.3
std::void_t<> - 33.4Afternotes
- VIFinal General Hints
34.Common C++17 Settings
- 34.1Value of
__cplusplus - 34.2Compatibility to C11
- 34.3Dealing with Signal Handlers
- 34.4Forward Progress Guarantees
- 34.5Afternotes
35.Deprecated and Removed Features
- 35.1Deprecated and Removed Core Language Features
- 35.1.1Throw Specifications
- 35.1.2Keyword
register - 35.1.3Disable
++forbool - 35.1.4Trigraphs
- 35.1.5Definition/Redeclaration of
staticconstexprMembers - 35.2Deprecated and Removed Library Features
- 35.2.1
auto_ptr - 35.2.2Algorithm
random_shuffle() - 35.2.3
unary_functionandbinary_function - 35.2.4
ptr_fun(),mem_fun(), and Binders - 35.2.5Allocator Support for
std::function<> - 35.2.6Deprecated IOStream Aliases
- 35.2.7Deprecated Library Features
- 35.3Afternotes
Glossary
- B
- bitmask type
- F
- full specialization
- I
- incomplete type
- P
- partial specialization
- S
- small/short string optimization (SSO)
- V
- variable template
- variadic template
