Cover....1
Title Page....2
Copyright and Credits....3
Contributors....5
About the reviewers....6
Table of Contents....8
Preface....18
Part 1: Under the Hood of C++ Programming....24
Chapter 1: Building C++ Applications....26
Technical requirements....27
Building C++ applications....27
Preprocessing....29
Compiling....32
Linking....35
Low-level programming with C++....40
Functions....40
Data and memory....46
Control flow....60
Details of OOP....63
Class relationships....73
Summary....75
Chapter 2: Beyond Object-Oriented Programming....76
Technical requirements....77
An introduction to OOP and the C++ object model....77
Understanding objects....77
Low-level details of objects....77
High-level details of objects....80
C++ object model....81
State....85
Identity....86
Behavior....87
Mimicking a class....88
Working with classes....90
Classes from a compiler perspective....92
Initialization and destruction....94
Copying objects....96
Moving objects....99
An lvalue reference....100
Rvalue references....101
Notes on operator overloading....103
Encapsulation and the public interface....105
Class relationships....108
Aggregation and composition....109
Under the hood of inheritance and polymorphism....110
Inheritance....110
Polymorphism....120
Virtual functions under the hood....122
Classical design patterns....125
The composite pattern....127
The decorator pattern....133
Design principles....138
The single responsibility principle....138
The open-closed principle....140
The Liskov substitution principle....142
The interface segregation principle....145
The dependency inversion principle....147
More UML in project design....148
The sequence diagram....148
Summary....153
Questions....153
Further reading....154
Chapter 3: Understanding and Designing Templates....156
Technical requirements....157
Motivation for using templates....157
Function templates....157
Syntax....158
Instantiation....159
Deduction....160
Specialization and overloading....160
Class templates....162
Syntax....162
Instantiation....163
Specialization....166
Understanding variadic templates....170
Syntax....170
Examples....171
Exploring template parameters and arguments....172
Template parameters....173
Non-type template parameter....173
Type template parameter....174
Template template parameter....176
Template arguments....177
Traits....181
Type trait implementation....181
Optimizing algorithms using traits....183
TMP and its applications....185
Summary....186
Questions....187
Further reading....187
Chapter 4: Template Meta Programming....190
Technical requirements....190
Back to basics (compile-time programming with templates)....191
Compile-time evaluation using constexpr....199
Constant expression-specified constructors (constexpr)....202
SFINAE AND enable_if<>....206
Argument substitution failure....207
Disabling templates with enable_if<>....210
Type traits....214
isFundamental....218
isArithmetic....219
isScalar....220
isConst....222
isVolatile....223
isPolymorphic....223
isAbstract....224
is_signed....225
Summary....225
Questions....226
Chapter 5: Memory Management and Smart Pointers....228
Technical requirements....229
Understanding computer memory....229
Designing a memory storage device....229
Understanding computer memory from a higher-level perspective....232
An example of memory management....243
Using smart pointers....246
Leveraging the RAII idiom....246
std::unique_ptr....249
std::shared_ptr and std::weak_ptr....251
Garbage collection....253
Using allocators....257
Types of allocators....258
Summary....265
Questions....266
Part 2: Designing Robust and Efficient Applications....268
Chapter 6: Digging into Data Structures and Algorithms in STL....270
Technical requirements....271
Sequential data structures....271
STL containers....276
Iterating containers....283
Concepts and iterators....287
Understanding concepts....287
Using iterators in C++20....289
Node-based data structures....290
Graphs and trees....295
Trees....295
Graphs....296
Hash tables....299
Algorithms....300
Search algorithms....300
Sorting....301
Summary....302
Further reading....302
Questions....303
Chapter 7: Advanced Data Structures....304
Technical requirements....306
B-trees....306
Searching....310
Insertion....313
Deletion....318
Implementation details of std::unordered_map....323
How std::unordered_map organizes element storing and how elements are inserted into or searched in std::unordered_map....324
Hash functions and strategies that are used to implement them....326
Digit selection....327
Folding....327
Using modulo....328
Collisions and how they are handled....329
Heaps and their applications....331
Advanced lists....341
Skip lists....342
XOR lists....347
Summary....349
Questions....350
Further reading....350
Chapter 8: Functional Programming....352
Technical requirements....353
Functional programming revealed....353
Using ranges....356
First-class and higher-order functions....360
Why use functional programming?....364
Principles of functional programming....366
Pure functions....366
Folding....368
Delving more deeply into recursion....369
Head recursion....372
Tail recursion....373
Metaprogramming in functional C++....374
Summary....377
Questions....378
Further reading....378
Chapter 9: Concurrency and Multithreading....380
Technical requirements....381
Understanding concurrency and multithreading....381
Processes....383
Threads....391
Working with threads....395
Waiting for threads....396
Using std::jthread....399
Passing arguments to the thread function....401
Managing threads and sharing data....402
Sharing data....405
Protecting shared data using a mutex....405
Avoiding deadlocks....406
Designing concurrent code....407
Introducing coroutines....409
Summary....412
Questions....412
Further reading....413
Chapter 10: Designing Concurrent Data Structures....414
Technical requirements....414
Thread safety....415
Lock-based concurrent data structures....415
A thread-safe singleton pattern....416
Synchronized counters....420
Concurrent stacks....422
Lock-free concurrent data structures....424
Using atomic types....425
Operations on atomic types....427
Lock-free stacks....429
A lock-free queue....432
A lock-free hashtable....433
A lock-free set....435
More operations on atomics....436
Summary....438
Questions....438
Further reading....438
Chapter 11: Designing World-Ready Applications....440
Technical requirements....440
Design patterns....441
Singleton....441
Factory....442
Adapter....443
Composite....443
Observer....444
Command....445
Applying design patterns....445
The problem....446
Trade-offs....446
Systemwide impact....446
Users....446
Using domain-driven design....446
An example of a real-world project....447
Summary....455
Questions....455
Further reading....456
Chapter 12: Incorporating Design Patterns in C++ Applications....458
Technical requirements....458
Design patterns in game development....459
The singleton pattern....459
The factory pattern....461
The flyway pattern....462
Design patterns in data-intensive applications....464
The proxy pattern....464
The decorator pattern....467
The iterator pattern....471
Design patterns in enterprise applications....471
SOA....472
Summary....472
Questions....473
Further reading....473
Chapter 13: Networking and Security....474
Technical requirements....474
Introduction to networks, the OSI model, and network programming using sockets....475
The OSI model....475
Network applications under the hood....477
Programming network applications using sockets....479
Understanding network protocols....480
Designing an echo server....483
Securing applications....486
Securing network applications....488
Summary....490
Questions....490
Further reading....491
Chapter 14: Debugging and Testing....492
Technical requirements....492
Understanding the root cause of an issue....492
RCA overview....493
Prevention is better than cure – good coding behavior....494
The uninitialized variable problem....495
Side effects in compound expressions....496
Mixed signed and unsigned problems....496
Order of evaluation problem....496
Compile-time checking versus runtime checking....497
Avoiding memory leaks....498
Debugging programs....499
Tools for debugging a C/C++ program....499
GDB overview....500
Examples of GDB....501
Setting breakpoints and inspection variable values....502
Practical debugging strategies....506
Static and dynamic analysis....507
Static analysis....507
Dynamic analysis....507
Testing, TDD, and BDD....508
Unit testing....509
TDD....511
BDD....512
Summary....513
Further reading....514
Chapter 15: Large-Scale Application Design....516
Technical requirements....517
The introduction of large-scale, cross-platform project organizing....517
Large-scale, cross-platform project organization in C++....517
A large-scale, cross-platform project in C++....518
Best practices and strategies for managing a large-scale, cross-platform project in C++....520
Horizontal and vertical scaling....521
Horizontal scaling....522
Vertical scaling....522
Scaling C++ applications....523
Horizontal scaling in C++....523
Vertical scaling in C++....523
Designing data-intensive applications....524
Data structure....526
Data processing....526
The main function....527
Summary....527
Questions....528
Further reading....529
Part 3: C++ in the AI World....530
Chapter 16: Understanding and Using C++ in Machine Learning Tasks....532
Technical requirements....533
Introduction to AI....533
Computer vision....535
NLP....537
Knowledge reasoning....538
ML....539
Understanding ML....540
Designing an algorithm that learns....542
Categories of ML....544
Applications of ML....546
Neural networks....547
Clustering....549
Regression analysis....550
C++ and ML....552
Summary....553
Questions....554
Further reading....554
Chapter 17: Using C++ in Data Science....556
Technical requirements....557
Introduction to data science....557
C++ example....558
Data capturing and manipulation....560
C++ example....561
Data cleansing and processing....563
C++ example....564
Applying machine learning algorithms....565
C++ example....567
Data visualization....569
C++ example....569
Summary....571
Questions....572
Further reading....572
Chapter 18: Designing and Implementing a Data Analysis Framework....574
Technical requirements....575
Using and processing statistical data types....575
C++ example....576
Working with tabular and rectangular data....578
C++ example....579
A complete ETL pipeline design strategy....581
C++ example....583
Summary....586
Questions....587
Further reading....587
Index....588
Other Books You May Enjoy....601
Are you an experienced C++ developer eager to take your skills to the next level? This updated edition of Expert C++ is tailored to propel you toward your goals.
This book takes you on a journey of building C++ applications while exploring advanced techniques beyond object-oriented programming. Along the way, you'll get to grips with designing templates, including template metaprogramming, and delve into memory management and smart pointers. Once you have a solid grasp of these foundational concepts, you'll advance to more advanced topics such as data structures with STL containers and explore advanced data structures with C++. Additionally, the book covers essential aspects like functional programming, concurrency, and multithreading, and designing concurrent data structures. It also offers insights into designing world-ready applications, incorporating design patterns, and addressing networking and security concerns. Finally, it adds to your knowledge of debugging and testing and large-scale application design.
With Expert C++ as your guide, you'll be empowered to push the boundaries of your C++ expertise and unlock new possibilities in software development.
This book will empower experienced C++ developers to achieve advanced proficiency, enabling them to build professional-grade applications with the latest features of C++17 and C++20. If you're an aspiring software engineer or computer science student, you'll able to master advanced C++ programming techniques through real-world applications that will prepare you for complex projects and real-world challenges.