Cover....1
Contents....6
Preface....26
PART I: Fundamentals....30
1 C++: The Comprehensive Guide....32
1.1 New and Modern....32
1.2 “Dan” Chapters....33
1.3 Presentation in This Book....34
1.4 Formatting Used....34
1.5 Let’s Talk Lingo....35
2 Programming in C++....36
2.1 Compiling....37
2.2 Translation Phases....38
2.3 Current Compilers....38
2.3.1 Gnu C++....39
2.3.2 Clang++ from LLVM....39
2.3.3 Microsoft Visual C++....39
2.3.4 Compiler in the Container....39
2.4 Development Environments....40
2.5 The Command Line under Ubuntu....42
2.5.1 Create a Program....43
2.5.2 Automate with Makefile....44
2.6 The Visual Studio Code IDE under Windows....45
2.7 Speed Up the Sample Program....52
3 C++ for Newcomers....54
4 The Basic Building Blocks of C++....62
4.1 A Quick Overview....65
4.1.1 Comments....65
4.1.2 The “include” Directive....65
4.1.3 The Standard Library....65
4.1.4 The “main()” Function....66
4.1.5 Types....66
4.1.6 Variables....66
4.1.7 Initialization....67
4.1.8 Output on the Console....68
4.1.9 Statements....68
4.2 A Detailed Walkthrough....69
4.2.1 Spaces, Identifiers, and Tokens....70
4.2.2 Comments....72
4.2.3 Functions and Arguments....73
4.2.4 Side Effect Operators....74
4.2.5 The “main” Function....75
4.2.6 Statements....77
4.2.7 Expressions....79
4.2.8 Allocations....80
4.2.9 Types....82
4.2.10 Variables: Declaration, Definition, and Initialization....88
4.2.11 Initialize with “auto”....89
4.2.12 Details on the Include Directive....91
4.2.13 Modules....92
4.2.14 Input and Output....93
4.2.15 The “std” Namespace....94
4.3 Operators....96
4.3.1 Operators and Operands....96
4.3.2 Overview of Operators....97
4.3.3 Arithmetic Operators....98
4.3.4 Bit-by-Bit Arithmetic....99
4.3.5 Composite Assignment....102
4.3.6 Post- and Preincrement and Post- and Predecrement....103
4.3.7 Relational Operators....103
4.3.8 Logical Operators....104
4.3.9 Pointer and Dereference Operators....105
4.3.10 Special Operators....106
4.3.11 Function-Like Operators....108
4.3.12 Operator Sequence....109
4.4 Built-In Data Types....110
4.4.1 Overview....111
4.4.2 Initialize Built-In Data Types....113
4.4.3 Integers....113
4.4.4 Floating-Point Numbers....126
4.4.5 Truth Values....140
4.4.6 Character Types....142
4.4.7 Complex Numbers....145
4.5 Undefined Behavior....148
5 Good Code, 1st Dan: Writing Readable Code....150
5.1 Comments....150
5.2 Documentation....151
5.3 Indentations and Line Length....152
5.4 Lines per Function and File....153
5.5 Brackets and Spaces....153
5.6 Names....155
6 Higher Data Types....158
6.1 The String Type “string”....159
6.1.1 Initialization....160
6.1.2 Functions and Methods....161
6.1.3 Other String Types....162
6.1.4 For Viewing Only: “string_view”....163
6.2 Streams....165
6.2.1 Input and Output Operators....165
6.2.2 “getline”....167
6.2.3 Files for Input and Output....167
6.2.4 Manipulators....169
6.2.5 The “endl” Manipulator....171
6.3 Container and Pointer....171
6.3.1 Container....171
6.3.2 Parameterized Types....172
6.4 The Simple Sequence Containers....173
6.4.1 “array”....173
6.4.2 “vector”....175
6.5 Algorithms....178
6.6 Pointers and C-Arrays....179
6.6.1 Pointer Types....179
6.6.2 C-Arrays....179
7 Functions....180
7.1 Declaration and Definition of a Function....181
7.2 Function Type....182
7.3 Using Functions....183
7.4 Defining a Function....184
7.5 More about Parameters....185
7.5.1 Call-by-Value....185
7.5.2 Call-by-Reference....186
7.5.3 Constant References....187
7.5.4 Call as Value, Reference, or Constant Reference?....188
7.6 Functional Body....189
7.7 Converting Parameters....191
7.8 Overloading Functions....193
7.9 Default Parameter....195
7.10 Arbitrary Number of Arguments....197
7.11 Alternative Notation for Function Declaration....197
7.12 Specialties....198
7.12.1 “noexcept”....198
7.12.2 Inline Functions....199
7.12.3 “constexpr”....199
7.12.4 Deleted Functions....200
7.12.5 Specialties in Class Methods....200
8 Statements in Detail....202
8.1 The Statement Block....205
8.1.1 Standalone Blocks and Variable Scope....206
8.2 The Empty Statement....207
8.3 Declaration Statement....208
8.3.1 Structured Binding....209
8.4 The Expression Statement....210
8.5 The “if” Statement....211
8.5.1 “if” with Initializer....214
8.5.2 Compile-Time “if”....214
8.6 The “while” Loop....215
8.7 The “do-while” Loop....217
8.8 The “for” Loop....218
8.9 The Range-Based “for” Loop....220
8.10 The “switch” Statement....221
8.11 The “break” Statement....226
8.12 The “continue” Statement....227
8.13 The “return” Statement....227
8.14 The “goto” Statement....228
8.15 The “try-catch” Block and “throw”....230
8.16 Summary....231
9 Expressions in Detail....232
9.1 Calculations and Side Effects....233
9.2 Types of Expressions....234
9.3 Literals....235
9.4 Identifiers....236
9.5 Parentheses....236
9.6 Function Call and Index Access....237
9.7 Assignment....237
9.8 Type Casting....239
10 Error Handling....242
10.1 Error Handling with Error Codes....244
10.2 What Is an Exception?....247
10.2.1 Throwing and Handling Exceptions....248
10.2.2 Unwinding the Call Stack....249
10.3 Minor Error Handling....250
10.4 Throwing the Exception Again: “rethrow”....250
10.5 The Order in “catch”....251
10.5.1 No “finally”....252
10.5.2 Standard Library Exceptions....252
10.6 Types for Exceptions....253
10.7 When an Exception Falls Out of “main”....254
11 Good Code, 2nd Dan: Modularization....256
11.1 Program, Library, Object File....256
11.2 Modules....257
11.3 Separating Functionalities....258
11.4 A Modular Example Project....259
11.4.1 Namespaces....262
11.4.2 Implementation....263
11.4.3 Using the Library....269
PART II: Object-Oriented Programming and More....272
12 From Structure to Class....274
12.1 Initialization....277
12.2 Returning Custom Types....278
12.3 Methods Instead of Functions....279
12.4 The Better “print”....282
12.5 An Output Like Any Other....284
12.6 Defining Methods Inline....285
12.7 Separate Implementation and Definition....286
12.8 Initialization via Constructor....287
12.8.1 Member Default Values in Declaration....290
12.8.2 Constructor Delegation....291
12.8.3 Default Values for Constructor Parameters....292
12.8.4 Do Not Call the “init” Method in the Constructor....293
12.8.5 Exceptions in the Constructor....294
12.9 Struct or Class?....294
12.9.1 Encapsulation....296
12.9.2 “public” and “private”, Struct and Class....296
12.9.3 Data with “struct”, Behavior with “class”....297
12.9.4 Initialization of Types with Private Data....297
12.10 Interim Recap....298
12.11 Using Custom Data Types....299
12.11.1 Using Classes as Values....301
12.11.2 Using Constructors....304
12.11.3 Type Conversions....305
12.11.4 Encapsulate and Decapsulate....307
12.11.5 Give Types a Local Name....311
12.12 Type Inference with “auto”....314
12.13 Custom Classes in Standard Containers....318
12.13.1 Three-Way Comparison: The Spaceship Operator....320
13 Namespaces and Qualifiers....322
13.1 The “std” Namespace....323
13.2 Anonymous Namespace....326
13.3 “static” Makes Local....328
13.4 “static” Likes to Share....329
13.5 Remote Initialization or “static inline” Data Fields....331
13.6 Guaranteed to Be Initialized at Compile Time with “constinit”....332
13.7 “static” Makes Permanent....332
13.8 “inline namespace”....334
13.9 Interim Recap....335
13.10 “const”....336
13.10.1 Const Parameters....337
13.10.2 Const Methods....338
13.10.3 “const” Variables....340
13.10.4 Const Returns....341
13.10.5 “const” Together with “static”....345
13.10.6 Even More Constant with “constexpr”....346
13.10.7 “if constexpr” for Compile-Time Decisions....349
13.10.8 C++20: “consteval”....351
13.10.9 “if consteval”....353
13.10.10 Un-“const” with “mutable”....354
13.10.11 Const-Correctness....354
13.10.12 Summary....356
13.11 Volatile with “volatile”....356
14 Good Code, 3rd Dan: Testing....360
14.1 Types of Tests....360
14.1.1 Refactoring....361
14.1.2 Unit Tests....362
14.1.3 Social or Solitary....363
14.1.4 Doppelgangers....365
14.1.5 Suites....366
14.2 Frameworks....367
14.2.1 Arrange, Act, Assert....369
14.2.2 Frameworks to Choose From....370
14.3 Boost.Test....371
14.4 Helper Macros for Assertions....375
14.5 An Example Project with Unit Tests....378
14.5.1 Private and Public Testing....379
14.5.2 An Automatic Test Module....380
14.5.3 Compile Test....383
14.5.4 Assemble the Test Suite Yourself....383
14.5.5 Testing Private Members....387
14.5.6 Parameterized Tests....388
15 Inheritance....390
15.1 Relationships....391
15.1.1 Has-a Composition....391
15.1.2 Has-a Aggregation....391
15.1.3 Is-a Inheritance....392
15.1.4 Instance-of versus Is-a Relationship....393
15.2 Inheritance in C++....393
15.3 Has-a versus Is-a....394
15.4 Finding Commonalities....395
15.5 Derived Types Extend....397
15.6 Overriding Methods....398
15.7 How Methods Work....399
15.8 Virtual Methods....401
15.9 Constructors in Class Hierarchies....403
15.10 Type Conversion in Class Hierarchies....404
15.10.1 Converting Up the Inheritance Hierarchy....404
15.10.2 Downcasting the Inheritance Hierarchy....405
15.10.3 References Also Retain Type Information....405
15.11 When to Use Virtual?....406
15.12 Other Designs for Extensibility....408
16 The Lifecycle of Classes....410
16.1 Creation and Destruction....411
16.2 Temporary: Short-Lived Values....413
16.3 The Destructor to the Constructor....415
16.3.1 No Destructor Needed....417
16.3.2 Resources in the Destructor....417
16.4 Yoda Condition....419
16.5 Construction, Destruction, and Exceptions....420
16.6 Copy....422
16.7 Assignment Operator....425
16.8 Removing Methods....428
16.9 Move Operations....429
16.9.1 What the Compiler Generates....433
16.10 Operators....434
16.11 Custom Operators in a Data Type....437
16.12 Special Class Forms....445
16.12.1 Abstract Classes and Methods....445
16.12.2 Enumeration Classes....447
17 Good Code, 4th Dan: Security, Quality, and Sustainability....450
17.1 The Rule of Zero....450
17.1.1 The Big Five....450
17.1.2 Helper Construct by Prohibition....451
17.1.3 The Rule of Zero and Its Application....452
17.1.4 Exceptions to the Rule of Zero....453
17.1.5 Rule of Zero, Rule of Three, Rule of Five, Rule of Four and a Half....455
17.2 Resource Acquisition Is Initialization....456
17.2.1 An Example with C....456
17.2.2 Owning Raw Pointers....458
17.2.3 From C to C++....459
17.2.4 It Doesn't Always Have to Be an Exception....461
17.2.5 Multiple Constructors....462
17.2.6 Multiphase Initialization....463
17.2.7 Define Where It Is Needed....463
17.2.8 “new” without Exceptions....463
18 Specials for Classes....466
18.1 Allowed to See Everything: “friend” Classes....466
18.1.1 “friend class” Example....468
18.2 Nonpublic Inheritance....470
18.2.1 Impact on the Outside World....472
18.2.2 Nonpublic Inheritance in Practice....474
18.3 Signature Classes as Interfaces....476
18.4 Multiple Inheritance....480
18.4.1 Multiple Inheritance in Practice....482
18.4.2 Caution with Pointer Type Conversions....486
18.4.3 The Observer Pattern as a Practical Example....488
18.5 Diamond-Shaped Multiple Inheritance: “virtual” for Class Hierarchies....489
18.6 Literal Data Types: “constexpr” for Constructors....494
19 Good Code, 5th Dan: Classical Object- Oriented Design....496
19.1 Objects in C++....498
19.2 Object-Oriented Design....499
19.2.1 SOLID....499
19.2.2 Don't Be STUPID....515
PART III: Advanced Topics....518
20 Pointers....520
20.1 Addresses....521
20.2 Pointer....522
20.3 Dangers of Aliasing....524
20.4 Heap Memory and Stack Memory....525
20.4.1 The Stack....525
20.4.2 The Heap....527
20.5 Smart Pointers....529
20.5.1 “unique_ptr”....531
20.5.2 “shared_ptr”....535
20.6 Raw Pointers....538
20.7 C-Arrays....542
20.7.1 Calculating with Pointers....543
20.7.2 Decay of C-Arrays....544
20.7.3 Dynamic C-Arrays....546
20.7.4 String Literals....547
20.8 Iterators....549
20.9 Pointers as Iterators....550
20.10 Pointers in Containers....551
20.11 The Exception: When Cleanup Is Not Necessary....551
21 Macros....554
21.1 The Preprocessor....555
21.2 Beware of Missing Parenthesis....559
21.3 Feature Macros....560
21.4 Information about the Source Code....560
21.5 Warning about Multiple Executions....561
21.6 Type Variability of Macros....562
21.7 Summary....565
22 Interface to C....566
22.1 Working with Libraries....567
22.2 C Header....568
22.3 C Resources....571
22.4 “void” Pointers....571
22.5 Reading Data....572
22.6 The Main Program....574
22.7 Summary....574
23 Templates....576
23.1 Function Templates....577
23.1.1 Overloading....578
23.1.2 A Type as Parameter....579
23.1.3 Function Body of a Function Template....579
23.1.4 Values as Template Parameters....582
23.1.5 Many Functions....583
23.1.6 Parameters with Extras....584
23.1.7 Method Templates are Just Function Templates....586
23.2 Function Templates in the Standard Library....587
23.2.1 Ranges instead of Containers as Template Parameters....588
23.2.2 Example: Information about Numbers....591
23.3 A Class as a Function....592
23.3.1 Values for a “Function” Parameter....593
23.3.2 C Function Pointer....594
23.3.3 The Somewhat Different Function....596
23.3.4 Practical Functors....599
23.3.5 Algorithms with Functors....601
23.3.6 Anonymous Functions: a.k.a. Lambda Expressions....601
23.3.7 Template Functions without “template”, but with “auto”....607
23.4 C++ Concepts....608
23.4.1 How to Read Concepts....608
23.4.2 How to Use Concepts....611
23.4.3 How to Write Concepts....613
23.4.4 Semantic Constraints....614
23.4.5 Interim Recap....615
23.5 Template Classes....615
23.5.1 Implementing Class Templates....616
23.5.2 Implementing Methods of Class Templates....617
23.5.3 Creating Objects from Class Templates....619
23.5.4 Class Templates with Multiple Formal Data Types....622
23.5.5 Class Templates with Nontype Parameters....624
23.5.6 Class Templates with Defaults....625
23.5.7 Specializing Class Templates....627
23.6 Templates with Variable Argument Count....629
23.6.1 “sizeof ...” Operator....632
23.6.2 Convert Parameter Pack to Tuple....632
23.7 Custom Literals....633
23.7.1 What Are Literals?....634
23.7.2 Naming Rules....634
23.7.3 Literal Processing Phases....635
23.7.4 Overloading Variants....635
23.7.5 User-Defined Literal Using Template....637
23.7.6 Raw or Cooked....640
23.7.7 Automatically Merged....641
23.7.8 Unicode Literals....641
PART IV: The Standard Library....644
24 Containers....646
24.1 Basics....647
24.1.1 Recurring....647
24.1.2 Abstract....648
24.1.3 Operations....649
24.1.4 Complexity....650
24.1.5 Containers and Their Iterators....652
24.1.6 Ranges Simplify Iterators....655
24.1.7 Ranges, Views, Concepts, Adapters, Generators, and Algorithms....658
24.1.8 Algorithms....659
24.2 Iterator Basics....659
24.2.1 Iterators from Containers....661
24.2.2 More Functionality with Iterators....662
24.3 Allocators: Memory Issues....664
24.4 Container Commonalities....667
24.5 An Overview of the Standard Container Classes....668
24.5.1 Type Aliases of Containers....669
24.6 The Sequential Container Classes....672
24.6.1 Commonalities and Differences....674
24.6.2 Methods of Sequence Containers....676
24.6.3 “vector”....678
24.6.4 “array”....697
24.6.5 “deque”....703
24.6.6 “list”....707
24.6.7 “forward_list”....710
24.7 Associative and Ordered....715
24.7.1 Commonalities and Differences....716
24.7.2 Methods of Ordered Associative Containers....717
24.7.3 “set”....718
24.7.4 “map”....732
24.7.5 “multiset”....739
24.7.6 “multimap”....744
24.8 Only Associative and Not Guaranteed....748
24.8.1 Hash Tables....748
24.8.2 Commonalities and Differences....753
24.8.3 Methods of Unordered Associative Containers....755
24.8.4 “unordered_set”....756
24.8.5 “unordered_map”....765
24.8.6 “unordered_multiset”....769
24.8.7 “unordered_multimap”....775
24.9 Container Adapters....778
24.10 Special Cases: “string”, “basic_string”, and “vector”....780
24.11 Special Cases: “vector”, “array”, and “bitset”....781
24.11.1 Dynamic and Compact: “vector”....782
24.11.2 Static: “array” and “bitset”....782
24.12 Special Case: Value Array with “valarray<>”....785
24.12.1 Element Properties....786
24.12.2 Initialize....788
24.12.3 Assignment....788
24.12.4 Insert and Delete....789
24.12.5 Accessing....789
24.12.6 Specialty: Manipulate All Data....789
24.12.7 Specialty: Slicing and Masking....790
25 Container Support....794
25.1 Algorithms....795
25.2 Iterators and Ranges....797
25.3 Iterator Adapter....799
25.4 Algorithms of the Standard Library....799
25.5 Parallel Execution....801
25.6 Lists of Algorithm Functions and Range Adapters....804
25.6.1 Range Adapters and Views....805
25.6.2 Ranges as Parameters (and More)....812
25.6.3 List of Nonmodifying Algorithms....814
25.6.4 Inherently Modifying Algorithms....819
25.6.5 Algorithms for Partitions....824
25.6.6 Algorithms for Sorting and Fast Searching in Sorted Ranges....825
25.6.7 Set Algorithms Represented by a Sorted Range....826
25.6.8 Heap Algorithms....828
25.6.9 Minimum and Maximum....829
25.6.10 Various Algorithms....829
25.7 Element-Linking Algorithms from “” and “”....830
25.8 Copy instead of Assignment: Values in Uninitialized Memory Areas....837
25.9 Custom Algorithms....839
25.10 Writing Custom Views and Range Adapters....841
26 Good Code, 6th Dan: The Right Container for Each Task....844
26.1 All Containers Arranged by Aspects....844
26.1.1 When Is a “vector” Not the Best Choice?....844
26.1.2 Always Sorted: “set”, “map”, “multiset”, and “multimap”....845
26.1.3 In Memory Contiguously: “vector”, “array”....845
26.1.4 Cheap Insertion: “list”....846
26.1.5 Low Memory Overhead: “vector”, “array”....847
26.1.6 Size Dynamic: All Except “array”....848
26.2 Recipes for Containers....849
26.2.1 Two Phases? “vector” as a Good “set” Replacement....849
26.2.2 Output the Contents of a Container to a Stream....851
26.2.3 So “array” Is Not That Static....851
26.3 Implementing Algorithms That Are Specialized Depending on the Container....855
27 Streams, Files, and Formatting....856
27.1 Input and Output Concept with Streams....856
27.2 Global, Predefined Standard Streams....857
27.2.1 Stream Operators << and >>....858
27.3 Methods for Stream Input and Output....859
27.3.1 Methods for Unformatted Output....859
27.3.2 Methods for Unformatted Input....861
27.4 Error Handling and Stream States....863
27.4.1 Methods for Handling Stream Errors....864
27.5 Manipulating and Formatting Streams....866
27.5.1 Manipulators....867
27.5.2 Creating Custom Manipulators without Arguments....872
27.5.3 Creating Custom Manipulators with Arguments....874
27.5.4 Directly Change Format Flags....875
27.6 Streams for File Input and Output....878
27.6.1 The “ifstream”, “ofstream”, and “fstream” Streams....878
27.6.2 Connecting to a File....878
27.6.3 Reading and Writing....883
27.6.4 Random Access....889
27.6.5 Synchronized Streams for Threads....890
27.7 Streams for Strings....891
27.7.1 Difference from “to_string”....895
27.7.2 “to_chars” and “format” Are More Flexible than “to_string”....896
27.7.3 Reading from a String....896
27.8 Stream Buffers....897
27.8.1 Access to the Stream Buffer of “iostream” Objects....898
27.8.2 “filebuf”....899
27.8.3 “stringbuf”....899
27.9 “filesystem”....899
27.10 Formatting....901
27.10.1 Simple Formatting....902
27.10.2 Formatting Custom Types....904
28 Standard Library: Extras....908
28.1 “pair” and “tuple”....908
28.1.1 Returning Multiple Values....909
28.2 Regular Expressions....916
28.2.1 Matching and Searching....917
28.2.2 The Result and Parts of It....917
28.2.3 Found Replacement....918
28.2.4 Rich in Variants....918
28.2.5 Iterators....919
28.2.6 Matches....919
28.2.7 Options....920
28.2.8 Speed....920
28.2.9 Standard Syntax, Slightly Shortened....921
28.2.10 Notes on Regular Expressions in C++....922
28.3 Randomness....925
28.3.1 Rolling a Die....926
28.3.2 True Randomness....928
28.3.3 Other Generators....928
28.3.4 Distributions....930
28.4 Mathematical....934
28.4.1 Fraction and Time: “” and “”....934
28.4.2 Predefined Suffixes for User-Defined Literals....956
28.5 System Error Handling with “system_error”....959
28.5.1 Overview....959
28.5.2 Principles....960
28.5.3 “error_code” and “error_condition”....961
28.5.4 Error Categories....965
28.5.5 Custom Error Codes....965
28.5.6 “system_error” Exception....966
28.6 Runtime Type Information: “” and “”....967
28.7 Helper Classes around Functors: “”....971
28.7.1 Function Objects....972
28.7.2 Function Generators....976
28.8 “optional” for a Single Value or No Value....979
28.9 “variant” for One of Several Types....979
28.10 “any” Holds Any Type....981
28.11 Special Mathematical Functions....982
28.12 Fast Conversion with “”....983
29 Threads: Programming with Concurrency....986
29.1 C++ Threading Basics....987
29.1.1 Starting Pure Threads....988
29.1.2 Terminating a Thread Prematurely....989
29.1.3 Waiting for a Thread....990
29.1.4 Consider Exceptions in the Starting Thread....991
29.1.5 Passing Parameters to a Thread Function....994
29.1.6 Moving a Thread....999
29.1.7 How Many Threads to Start?....1001
29.1.8 Which Thread Am I?....1003
29.2 Shared Data....1004
29.2.1 Data Races....1004
29.2.2 Latch....1007
29.2.3 Barriers....1007
29.2.4 Mutexes....1009
29.2.5 Interface Design for Multithreading....1011
29.2.6 Locks Can Lead to Deadlock....1016
29.2.7 More Flexible Locking with “unique_lock”....1018
29.3 Other Synchronization Options....1020
29.3.1 Call Only Once with “once_flag” and “call_once”....1020
29.3.2 Locking with “recursive_mutex”....1022
29.4 In Its Own Storage with “thread_local”....1023
29.5 Waiting for Events with “condition_variable”....1024
29.5.1 “notify_all”....1027
29.5.2 Synchronize Output....1028
29.6 Waiting Once with “future”....1029
29.6.1 Launch Policies....1030
29.6.2 Wait Until a Certain Time....1031
29.6.3 Exception Handling with “future”....1034
29.6.4 “promise”....1036
29.7 Atomics....1039
29.7.1 Overview of the Operations....1041
29.7.2 Memory Order....1042
29.7.3 Example....1044
29.8 Coroutines....1045
29.8.1 Coroutines in the Compiler....1045
29.8.2 Generator....1046
29.8.3 Coroutines with “promise_type”....1047
29.9 Summary....1050
29.9.1 “” Header....1050
29.9.2 “” and “” Headers....1050
29.9.3 “” and “” Headers....1051
29.9.4 “” Header....1051
29.9.5 “” Header....1052
29.9.6 “” Header....1052
29.9.7 “” Header....1052
30 Good Code, 7th Dan: Guidelines....1054
30.1 Guideline Support Library....1055
30.2 C++ Core Guidelines....1055
30.2.1 Motivation....1056
30.2.2 Type Safety....1057
30.2.3 Use RAII....1058
30.2.4 Class Hierarchies....1061
30.2.5 Generic Programming....1063
30.2.6 Do Not Be Confused by Anachronisms....1066
Appendices....1068
A Cheat Sheet....1068
B The Author....1072
Index....1074
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.
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.
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.
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.