Book Image

Advanced C++ Programming Cookbook

By : Dr. Rian Quinn
Book Image

Advanced C++ Programming Cookbook

By: Dr. Rian Quinn

Overview of this book

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.
Table of Contents (15 chapters)

To get the most out of this book

We assume that you have written C++ before and are already familiar with some modern C++ features.

This book uses Ubuntu to provide examples that you can compile and run yourself as you read the book. We assume you have some basic knowledge of Ubuntu, how to install it, and how to use a Linux terminal.

We use a disassembler in some of the recipes to better understand what the compiler is doing under the hood. Although you do not need to know how to read the assembly to understand what is being taught, a basic understanding of x86_64 assembly will help.

Download the example code files

You can download the example code files for this book from your account at www.packt.com. If you purchased this book elsewhere, you can visit www.packtpub.com/support and register to have the files emailed directly to you.

You can download the code files by following these steps:

  1. Log in or register at www.packt.com.
  2. Select the Support tab.
  3. Click on Code Downloads.
  4. Enter the name of the book in the Search box and follow the onscreen instructions.

Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:

  • WinRAR/7-Zip for Windows
  • Zipeg/iZip/UnRarX for Mac
  • 7-Zip/PeaZip for Linux

The code bundle for the book is also hosted on GitHub at https://github.com/PacktPublishing/Advanced-CPP-Programming-CookBook. In case there's an update to the code, it will be updated on the existing GitHub repository.

We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!

Code in Action

Conventions used

There are a number of text conventions used throughout this book.

constexpr: Indicates code words in text, numbers, folder names, filenames, file extensions, pathnames, dummy URLs, and user input. Here is an example: "The noexcept specifier is used to tell the compiler whether a function may or may not throw a C++ exception."

A block of code is set as follows:

int main(void)
{
the_answer is;
return 0;
}

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

int main(void)
{
auto execute_on_exit = finally{[]{
std::cout << "The answer is: 42\n";
}};
}

Any command-line input or output is written as follows:

> mkdir build && cd build
> cmake ..
> make recipe04_examples

Bold: Indicates a new term, an important word, or words that you see onscreen. For example, important words appear in the text like this. Here is an example: "In this recipe, we will learn why throwing exceptions in a destructor is a bad idea."

Warnings or important notes appear like this.
Tips and tricks appear like this.