Expert C++ - Second Edition

Book description

Take your C++ skills to the next level with expert insights on advanced techniques, design patterns, and high-performance programming Purchase of the print or Kindle book includes a free PDF eBook

Key Features

  • Master templates, metaprogramming, and advanced functional programming techniques to elevate your C++ skills
  • Design scalable and efficient C++ applications with the latest features of C++17 and C++20
  • Explore real-world examples and essential design patterns to optimize your code

Book Description

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.

What you will learn

  • Go beyond the basics to explore advanced C++ programming techniques
  • Develop proficiency in advanced data structures and algorithm design with C++17 and C++20
  • Implement best practices and design patterns to build scalable C++ applications
  • Master C++ for machine learning, data science, and data analysis framework design
  • Design world-ready applications, incorporating networking and security considerations
  • Strengthen your understanding of C++ concurrency, multithreading, and optimizing performance with concurrent data structures

Who this book is for

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 be able to master advanced C++ programming techniques through real-world applications that will prepare you for complex projects and real-world challenges.

Table of contents

  1. Expert C++
  2. Contributors
  3. About the authors
  4. About the reviewers
  5. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
    4. Download the example code files
    5. Conventions used
    6. Get in touch
    7. Share Your Thoughts
    8. Download a free PDF copy of this book
  6. Part 1:Under the Hood of C++ Programming
  7. Chapter 1: Building C++ Applications
    1. Technical requirements
    2. Building C++ applications
      1. Preprocessing
      2. Compiling
      3. Linking
    3. Low-level programming with C++
      1. Functions
      2. Data and memory
      3. Control flow
      4. Details of OOP
      5. Class relationships
    4. Summary
  8. Chapter 2: Beyond Object-Oriented Programming
    1. Technical requirements
    2. An introduction to OOP and the C++ object model
      1. Understanding objects
      2. Low-level details of objects
      3. High-level details of objects
      4. C++ object model
      5. State
      6. Identity
      7. Behavior
      8. Mimicking a class
      9. Working with classes
      10. Classes from a compiler perspective
      11. Initialization and destruction
      12. Copying objects
      13. Moving objects
      14. An lvalue reference
      15. Rvalue references
      16. Notes on operator overloading
      17. Encapsulation and the public interface
      18. Class relationships
      19. Aggregation and composition
    3. Under the hood of inheritance and polymorphism
      1. Inheritance
      2. Polymorphism
      3. Virtual functions under the hood
    4. Classical design patterns
      1. The composite pattern
      2. The decorator pattern
    5. Design principles
      1. The single responsibility principle
      2. The open-closed principle
      3. The Liskov substitution principle
      4. The interface segregation principle
      5. The dependency inversion principle
    6. More UML in project design
      1. The sequence diagram
    7. Summary
    8. Questions
    9. Further reading
  9. Chapter 3: Understanding and Designing Templates
    1. Technical requirements
    2. Motivation for using templates
    3. Function templates
      1. Syntax
      2. Instantiation
      3. Deduction
      4. Specialization and overloading
    4. Class templates
      1. Syntax
      2. Instantiation
      3. Specialization
    5. Understanding variadic templates
      1. Syntax
      2. Examples
    6. Exploring template parameters and arguments
      1. Template parameters
      2. Non-type template parameter
      3. Type template parameter
      4. Template template parameter
      5. Template arguments
    7. Traits
    8. Type trait implementation
    9. Optimizing algorithms using traits
    10. TMP and its applications
    11. Summary
    12. Questions
    13. Further reading
  10. Chapter 4: Template Meta Programming
    1. Technical requirements
    2. Back to basics (compile-time programming with templates)
    3. Compile-time evaluation using constexpr
      1. Constant expression-specified constructors (constexpr)
    4. SFINAE AND enable_if<>
      1. Argument substitution failure
      2. Disabling templates with enable_if<>
    5. Type traits
      1. isFundamental
      2. isArithmetic
      3. isScalar
      4. isConst
      5. isVolatile
      6. isPolymorphic
      7. isAbstract
      8. is_signed
    6. Summary
    7. Questions
  11. Chapter 5: Memory Management and Smart Pointers
    1. Technical requirements
    2. Understanding computer memory
      1. Designing a memory storage device
      2. Understanding computer memory from a higher-level perspective
      3. An example of memory management
    3. Using smart pointers
      1. Leveraging the RAII idiom
      2. std::unique_ptr
      3. std::shared_ptr and std::weak_ptr
    4. Garbage collection
    5. Using allocators
      1. Types of allocators
    6. Summary
    7. Questions
  12. Part 2: Designing Robust and Efficient Applications
  13. Chapter 6: Digging into Data Structures and Algorithms in STL
    1. Technical requirements
    2. Sequential data structures
      1. STL containers
    3. Iterating containers
    4. Concepts and iterators
      1. Understanding concepts
    5. Using iterators in C++20
    6. Node-based data structures
    7. Graphs and trees
      1. Trees
      2. Graphs
    8. Hash tables
    9. Algorithms
      1. Search algorithms
      2. Sorting
    10. Summary
    11. Further reading
    12. Questions
  14. Chapter 7: Advanced Data Structures
    1. Technical requirements
    2. B-trees
    3. Searching
      1. Insertion
      2. Deletion
    4. Implementation details of std::unordered_map
    5. How std::unordered_map organizes element storing and how elements are inserted into or searched in std::unordered_map
    6. Hash functions and strategies that are used to implement them
      1. Digit selection
      2. Folding
      3. Using modulo
      4. Collisions and how they are handled
    7. Heaps and their applications
    8. Advanced lists
      1. Skip lists
      2. XOR lists
    9. Summary
    10. Questions
    11. Further reading
  15. Chapter 8: Functional Programming
    1. Technical requirements
    2. Functional programming revealed
    3. Using ranges
    4. First-class and higher-order functions
      1. Why use functional programming?
      2. Principles of functional programming
    5. Pure functions
      1. Folding
    6. Delving more deeply into recursion
      1. Head recursion
      2. Tail recursion
    7. Metaprogramming in functional C++
    8. Summary
    9. Questions
    10. Further reading
  16. Chapter 9: Concurrency and Multithreading
    1. Technical requirements
    2. Understanding concurrency and multithreading
      1. Processes
      2. Threads
    3. Working with threads
      1. Waiting for threads
      2. Using std::jthread
      3. Passing arguments to the thread function
    4. Managing threads and sharing data
      1. Sharing data
      2. Protecting shared data using a mutex
      3. Avoiding deadlocks
    5. Designing concurrent code
      1. Introducing coroutines
    6. Summary
    7. Questions
    8. Further reading
  17. Chapter 10: Designing Concurrent Data Structures
    1. Technical requirements
    2. Thread safety
    3. Lock-based concurrent data structures
      1. A thread-safe singleton pattern
      2. Synchronized counters
      3. Concurrent stacks
    4. Lock-free concurrent data structures
      1. Using atomic types
      2. Operations on atomic types
      3. Lock-free stacks
      4. A lock-free queue
      5. A lock-free hashtable
      6. A lock-free set
      7. More operations on atomics
    5. Summary
    6. Questions
    7. Further reading
  18. Chapter 11: Designing World-Ready Applications
    1. Technical requirements
    2. Design patterns
      1. Singleton
      2. Factory
      3. Adapter
      4. Composite
      5. Observer
      6. Command
    3. Applying design patterns
      1. The problem
      2. Trade-offs
      3. Systemwide impact
      4. Users
      5. Using domain-driven design
    4. An example of a real-world project
    5. Summary
    6. Questions
    7. Further reading
  19. Chapter 12: Incorporating Design Patterns in C++ Applications
    1. Technical requirements
    2. Design patterns in game development
      1. The singleton pattern
      2. The factory pattern
      3. The flyway pattern
    3. Design patterns in data-intensive applications
      1. The proxy pattern
      2. The decorator pattern
      3. The iterator pattern
    4. Design patterns in enterprise applications
      1. SOA
    5. Summary
    6. Questions
    7. Further reading
  20. Chapter 13: Networking and Security
    1. Technical requirements
    2. Introduction to networks, the OSI model, and network programming using sockets
      1. The OSI model
      2. Network applications under the hood
      3. Programming network applications using sockets
    3. Understanding network protocols
    4. Designing an echo server
    5. Securing applications
    6. Securing network applications
    7. Summary
    8. Questions
    9. Further reading
  21. Chapter 14: Debugging and Testing
    1. Technical requirements
    2. Understanding the root cause of an issue
      1. RCA overview
      2. Prevention is better than cure – good coding behavior
      3. The uninitialized variable problem
      4. Side effects in compound expressions
      5. Mixed signed and unsigned problems
      6. Order of evaluation problem
      7. Compile-time checking versus runtime checking
      8. Avoiding memory leaks
    3. Debugging programs
      1. Tools for debugging a C/C++ program
      2. GDB overview
      3. Examples of GDB
      4. Setting breakpoints and inspection variable values
      5. Practical debugging strategies
    4. Static and dynamic analysis
      1. Static analysis
      2. Dynamic analysis
    5. Testing, TDD, and BDD
      1. Unit testing
      2. TDD
      3. BDD
    6. Summary
    7. Further reading
  22. Chapter 15: Large-Scale Application Design
    1. Technical requirements
    2. The introduction of large-scale, cross-platform project organizing
      1. Large-scale, cross-platform project organization in C++
      2. A large-scale, cross-platform project in C++
      3. Best practices and strategies for managing a large-scale, cross-platform project in C++
    3. Horizontal and vertical scaling
      1. Horizontal scaling
      2. Vertical scaling
    4. Scaling C++ applications
      1. Horizontal scaling in C++
      2. Vertical scaling in C++
    5. Designing data-intensive applications
      1. Data structure
      2. Data processing
      3. The main function
    6. Summary
    7. Questions
    8. Further reading
  23. Part 3:C++ in the AI World
  24. Chapter 16: Understanding and Using C++ in Machine Learning Tasks
    1. Technical requirements
    2. Introduction to AI
      1. Computer vision
      2. NLP
      3. Knowledge reasoning
    3. ML
      1. Understanding ML
      2. Designing an algorithm that learns
      3. Categories of ML
      4. Applications of ML
    4. Neural networks
    5. Clustering
    6. Regression analysis
    7. C++ and ML
    8. Summary
    9. Questions
    10. Further reading
  25. Chapter 17: Using C++ in Data Science
    1. Technical requirements
    2. Introduction to data science
      1. C++ example
    3. Data capturing and manipulation
      1. C++ example
    4. Data cleansing and processing
      1. C++ example
    5. Applying machine learning algorithms
      1. C++ example
    6. Data visualization
      1. C++ example
    7. Summary
    8. Questions
    9. Further reading
  26. Chapter 18: Designing and Implementing a Data Analysis Framework
    1. Technical requirements
    2. Using and processing statistical data types
      1. C++ example
    3. Working with tabular and rectangular data
      1. C++ example
    4. A complete ETL pipeline design strategy
      1. C++ example
    5. Summary
    6. Questions
    7. Further reading
  27. Index
    1. Why subscribe?
  28. Other Books You May Enjoy
    1. Packt is searching for authors like you
    2. Share Your Thoughts
    3. Download a free PDF copy of this book

Product information

  • Title: Expert C++ - Second Edition
  • Author(s): Marcelo Guerra Hahn, Araks Tigranyan, John Asatryan, Vardan Grigoryan, Shunguang Wu
  • Release date: August 2023
  • Publisher(s): Packt Publishing
  • ISBN: 9781804617830