0%

Book Description

A recipe-based guide to refining your C++ programming skills with the help of coding best practices, advanced programming concepts, and the latest features of C++17 and C++20

Key Features

  • Learn how to develop and design your own libraries
  • Find solutions to your app development problems and implement them in a highly reusable manner, following library development best practices
  • Explore advanced C++ features such as containers, coroutines, and modules

Book Description

If you think you've mastered C++ and know everything it takes to write robust applications, you'll be in for a surprise. With this book, you'll gain comprehensive insights into C++, covering exclusive tips and interesting techniques to enhance your app development process.

You'll kick off with the basic principles of library design and development, which will help you understand how to write reusable and maintainable code. You'll then discover the importance of exception safety, and how you can avoid unexpected errors or bugs in your code. The book will take you through the modern elements of C++, such as move semantics, type deductions, and coroutines. As you advance, you'll delve into template programming - the standard tool for most library developers looking to achieve high code reusability. You'll explore the STL and learn how to avoid common pitfalls while implementing templates. Later, you'll learn about the problems of multithreaded programming such as data races, deadlocks, and thread starvation. You'll also learn high-performance programming by using benchmarking tools and libraries. Finally, you'll discover advanced techniques for debugging and testing to ensure code reliability.

By the end of this book, you'll have become an expert at C++ programming and will have gained the skills to solve complex development problems with ease.

What you will learn

  • Solve common C++ development problems by implementing solutions in a more generic and reusable way
  • Achieve different levels of exception safety guarantees by introducing precise declarations
  • Write library-quality code that meets professional standards
  • Practice writing reliable, performant code that exposes consistent behavior in programs
  • Understand why you need to implement design patterns and how it's done
  • Work with complex examples to understand various aspects of good library design

Who this book is for

This book is for intermediate and expert-level C++ developers who are looking to explore the lesser known functionalities of the language to improve the efficiency of their code and the way they develop applications. Basic knowledge of object-oriented programming concepts and the Standard Template Library (STL) is assumed.

Table of Contents

  1. Title Page
  2. Copyright and Credits
    1. Advanced C++ Programming Cookbook
  3. Dedication
  4. About Packt
    1. Why subscribe?
  5. Contributors
    1. About the author
    2. About the reviewers
    3. Packt is searching for authors like you
  6. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
      1. Download the example code files
      2. Code in Action
      3. Conventions used
    4. Sections
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. There's more…
      5. See also
    5. Get in touch
      1. Reviews
  7. Getting Started with Library Development
    1. Technical requirements
    2. Understanding the principle of least surprise
      1. Getting ready
      2. How to do it...
      3. How it works...
        1. Example 1
        2. Example 2
        3. Example 3
        4. Example 4
        5. Example 5
        6. Example 6
        7. Example 7
        8. Example 8
        9. Example 9
    3. How to namespace everything
      1. Getting ready
      2. How to do it...
      3. How it works...
        1. Example 1
        2. Example 2
    4. Header-only libraries
      1. Getting ready
      2. How to do it...
      3. How it works...
        1. How to handle includes
        2. Global variables
        3. Issues with C-style macros
        4. How to implement a large library as header-only
    5. Learning library development best practices
      1. Getting ready
      2. How to do it...
      3. How it works... 
        1. What about warnings?
        2. Static and dynamic analysis
        3. Documentation
        4. CII Best Practices
    6. Learning how to use the boost APIs
      1. Getting ready
      2. How to do it...
      3. How it works... 
        1. Example 1
        2. Example 2
      4. See also
  8. Using Exceptions for Error Handling
    1. Technical requirements
    2. Using the noexcept specifier
      1. Getting ready
      2. How to do it...
      3. How it works...
    3. Using the noexcept operator
      1. Getting ready
      2. How to do it...
      3. How it works...
    4. Using RAII
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. Learning why to never throw exceptions in destructors
      1. Getting ready
      2. How to do it...
      3. How it works...
    6. Easily creating your own exception classes
      1. Getting ready
      2. How to do it...
      3. How it works...
  9. Implementing Move Semantics
    1. Technical requirements
    2. Using compiler-generated special class member functions and the Big Five
      1. Getting ready
      2. How to do it...
      3. How it works...
    3. Making your class movable
      1. Getting ready
      2. How to do it...
      3. How it works...
    4. Move-only types
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. Implementing the noexcept move constructor
      1. Getting ready
      2. How to do it...
      3. How it works...
    6. Learning to be wary of const&&
      1. Getting ready
      2. How to do it...
      3. How it works...
    7. Referencing qualified member functions
      1. Getting ready
      2. How to do it...
      3. How it works...
    8. Exploring objects that cannot be moved or copied
      1. Getting ready
      2. How to do it...
      3. How it works...
  10. Using Templates for Generic Programming
    1. Technical requirements
    2. Implementing SFINAE
      1. Getting ready
      2. How to do it...
      3. How it works...
    3. Learning perfect forwarding
      1. Getting ready
      2. How to do it...
      3. How it works...
    4. Using if constexpr
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. Using tuples to work with parameter packs
      1. Getting ready
      2. How to do it...
      3. How it works...
    6. Using type traits to overload functions and objects
      1. Getting ready
      2. How to do it...
      3. How it works...
    7. Learning how to implement template<auto>
      1. Getting ready
      2. How to do it...
      3. How it works...
    8. Working with explicit template declarations
      1. Getting ready
      2. How to do it...
      3. How it works...
  11. Concurrency and Synchronization
    1. Technical requirements
    2. Working with mutexes
      1. Getting ready
      2. How to do it...
      3. How it works...
        1. std::mutex
        2. std::lock_guard
        3. std::recursive_mutex
        4. std::shared_mutex
        5. std::timed_mutex
    3. Using atomic data types
      1. Getting ready
      2. How to do it...
      3. How it works...
    4. Understanding what const & mutable mean in the context of multiple threads
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. Making a class thread-safe
      1. Getting ready
      2. How to do it...
      3. How it works...
    6. Synchronization wrappers and how to implement them
      1. Getting ready
      2. How to do it...
      3. How it works...
    7. Blocking operations versus asynchronous programming
      1. Getting ready
      2. How to do it...
      3. How it works...
    8. Working with promises and futures
      1. Getting ready
      2. How to do it...
      3. How it works...
  12. Optimizing Your Code for Performance
    1. Technical requirements
    2. Benchmarking your code
      1. Getting ready
      2. How to do it...
      3. How it works...
    3. Looking at assembly code
      1. Getting ready
      2. How to do it...
      3. How it works...
    4. Reducing the number of memory allocations
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. Declaring noexcept
      1. Getting ready
      2. How to do it...
      3. How it works...
  13. Debugging and Testing
    1. Technical requirements
    2. Getting to grips with unit testing
      1. Getting ready
      2. How to do it...
      3. How it works...
    3. Working with ASAN, the address sanitizer
      1. Getting ready
      2. How to do it...
      3. How it works...
        1. Memory leak error
        2. Memory deleted twice
        3. Accessing invalid memory 
        4. Using memory after deleting it
        5. Deleting memory that was never allocated
    4. Working with UBSAN, the undefined behavior sanitizer
      1. Getting ready
      2. How to do it...
      3. How it works...
        1. Divide-by-zero errors
        2. Null-pointer dereferences
        3. Out-of-bounds errors
        4. Overflow errors
    5. Using #ifndef NDEBUG to conditionally execute additional checks
      1. Getting ready
      2. How to do it...
      3. How it works...
  14. Creating and Implementing Your Own Container
    1. Technical requirements
    2. Using a simple wrapper around std::vector
      1. Getting ready
      2. How to do it...
      3. How it works...
        1. Default constructor
        2. Custom allocator constructor
        3. Count constructors
        4. Copy/move constructors
        5. Initializer list constructor
        6. Usage
        7. Adding elements to our container
        8. Usage of push/emplace
    3. Adding the relevant parts of the std::set API
      1. Getting ready
      2. How to do it...
      3. How it works...
    4. Working with iterators
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. Adding the relevant parts of the std::vector API
      1. Getting ready
      2. How to do it...
      3. How it works...
  15. Exploring Type Erasure
    1. Technical requirements
    2. How to erase a type with inheritance
      1. Getting ready
      2. How to do it...
      3. How it works...
    3. Using C++ templates to write generic functions
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    4. Learning the C++ type eraser pattern
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. Implementing delegates with type erasing
      1. Getting ready
      2. How to do it...
      3. How it works...
        1. Adding a function signature to our delegate
        2. Adding const support to our delegate
        3. Adding support for one-to-many to our delegate
        4. Adding support for non-member functions to our delegate
  16. An In-Depth Look at Dynamic Allocation
    1. Technical requirements
    2. Comparing std::shared_ptr and std::unique_ptr
      1. Getting ready
      2. How to do it...
      3. How it works...
    3. Converting from a std::unique_ptr into a std::shared_ptr
      1. Getting ready
      2. How to do it...
      3. How it works...
    4. Working with circular references
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. Typecasting with smart pointers
      1. Getting ready
      2. How to do it...
      3. How it works...
    6. The heap under a microscope
      1.  Getting ready
      2. How to do it...
      3. How it works...
  17. Common Patterns in C++
    1. Technical requirements
    2. Learning the factory pattern
      1. Getting ready
      2. How to do it...
      3. How it works...
    3. Using the singleton pattern properly
      1. Getting ready
      2. How to do it...
      3. How it works...
    4. Extending your objects with the decorator pattern
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. Adding communication with the observer pattern
      1. Getting ready
      2. How to do it...
      3. How it works...
    6. Improving performance with static polymorphism
      1. Getting ready
      2. How to do it...
      3. How it works...
  18. A Closer Look at Type Deduction
    1. Technical requirements
    2. Using auto and type deduction
      1. Getting ready
      2. How to do it...
      3. How it works...
    3. Learning how decltype type deduction rules work
      1. Getting ready
      2. How to do it...
      3. How it works...
    4. Working with template function type deduction
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. Leveraging template class type deduction in C++17
      1. Getting ready
      2. How to do it...
      3. How it works...
    6. Working with user-defined type deduction in C++17
      1. Getting ready
      2. How to do it...
      3. How it works...
  19. Bonus - Using C++20 Features
    1. Technical requirements
    2. Looking at Concepts in C++20
      1. Getting ready
      2. How to do it...
      3. How it works...
    3. Working with Modules in C++20
      1. Getting ready
      2. How to do it...
      3. How it works...
    4. Introducing std::span, a new view on arrays
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. Working with Ranges in C++20
      1. Getting ready
      2. How to do it...
      3. How it works...
    6. Learning how to use Coroutines in C++20
      1. Getting ready
      2. How to do it...
      3. How it works...
  20. Other Books You May Enjoy
    1. Leave a review - let other readers know what you think
3.144.103.10