Expert C++
eBook - ePub

Expert C++

Become a proficient programmer by learning coding best practices with C++17 and C++20's latest features

Vardan Grigoryan, Shunguang Wu

Buch teilen
  1. 606 Seiten
  2. English
  3. ePUB (handyfreundlich)
  4. Über iOS und Android verfügbar
eBook - ePub

Expert C++

Become a proficient programmer by learning coding best practices with C++17 and C++20's latest features

Vardan Grigoryan, Shunguang Wu

Angaben zum Buch
Buchvorschau
Inhaltsverzeichnis
Quellenangaben

Über dieses Buch

Design and architect real-world scalable C++ applications by exploring advanced techniques in low-level programming, object-oriented programming (OOP), the Standard Template Library (STL), metaprogramming, and concurrency

Key Features

  • Design professional-grade, maintainable apps by learning advanced concepts such as functional programming, templates, and networking
  • Apply design patterns and best practices to solve real-world problems
  • Improve the performance of your projects by designing concurrent data structures and algorithms

Book Description

C++ has evolved over the years and the latest release – C++20 – is now available. Since C++11, C++ has been constantly enhancing the language feature set. With the new version, you'll explore an array of features such as concepts, modules, ranges, and coroutines. This book will be your guide to learning the intricacies of the language, techniques, C++ tools, and the new features introduced in C++20, while also helping you apply these when building modern and resilient software.

You'll start by exploring the latest features of C++, and then move on to advanced techniques such as multithreading, concurrency, debugging, monitoring, and high-performance programming. The book will delve into object-oriented programming principles and the C++ Standard Template Library, and even show you how to create custom templates. After this, you'll learn about different approaches such as test-driven development (TDD), behavior-driven development (BDD), and domain-driven design (DDD), before taking a look at the coding best practices and design patterns essential for building professional-grade applications. Toward the end of the book, you will gain useful insights into the recent C++ advancements in AI and machine learning.

By the end of this C++ programming book, you'll have gained expertise in real-world application development, including the process of designing complex software.

What you will learn

  • Understand memory management and low-level programming in C++ to write secure and stable applications
  • Discover the latest C++20 features such as modules, concepts, ranges, and coroutines
  • Understand debugging and testing techniques and reduce issues in your programs
  • Design and implement GUI applications using Qt5
  • Use multithreading and concurrency to make your programs run faster
  • Develop high-end games by using the object-oriented capabilities of C++
  • Explore AI and machine learning concepts with C++

Who this book is for

This C++ book is for experienced C++ developers who are looking to take their knowledge to the next level and perfect their skills in building professional-grade applications.

Häufig gestellte Fragen

Wie kann ich mein Abo kündigen?
Gehe einfach zum Kontobereich in den Einstellungen und klicke auf „Abo kündigen“ – ganz einfach. Nachdem du gekündigt hast, bleibt deine Mitgliedschaft für den verbleibenden Abozeitraum, den du bereits bezahlt hast, aktiv. Mehr Informationen hier.
(Wie) Kann ich Bücher herunterladen?
Derzeit stehen all unsere auf Mobilgeräte reagierenden ePub-Bücher zum Download über die App zur Verfügung. Die meisten unserer PDFs stehen ebenfalls zum Download bereit; wir arbeiten daran, auch die übrigen PDFs zum Download anzubieten, bei denen dies aktuell noch nicht möglich ist. Weitere Informationen hier.
Welcher Unterschied besteht bei den Preisen zwischen den Aboplänen?
Mit beiden Aboplänen erhältst du vollen Zugang zur Bibliothek und allen Funktionen von Perlego. Die einzigen Unterschiede bestehen im Preis und dem Abozeitraum: Mit dem Jahresabo sparst du auf 12 Monate gerechnet im Vergleich zum Monatsabo rund 30 %.
Was ist Perlego?
Wir sind ein Online-Abodienst für Lehrbücher, bei dem du für weniger als den Preis eines einzelnen Buches pro Monat Zugang zu einer ganzen Online-Bibliothek erhältst. Mit über 1 Million Büchern zu über 1.000 verschiedenen Themen haben wir bestimmt alles, was du brauchst! Weitere Informationen hier.
Unterstützt Perlego Text-zu-Sprache?
Achte auf das Symbol zum Vorlesen in deinem nächsten Buch, um zu sehen, ob du es dir auch anhören kannst. Bei diesem Tool wird dir Text laut vorgelesen, wobei der Text beim Vorlesen auch grafisch hervorgehoben wird. Du kannst das Vorlesen jederzeit anhalten, beschleunigen und verlangsamen. Weitere Informationen hier.
Ist Expert C++ als Online-PDF/ePub verfügbar?
Ja, du hast Zugang zu Expert C++ von Vardan Grigoryan, Shunguang Wu im PDF- und/oder ePub-Format sowie zu anderen beliebten Büchern aus Computer Science & Programming in C++. Aus unserem Katalog stehen dir über 1 Million Bücher zur Verfügung.

Information

Jahr
2020
ISBN
9781838554767

Section 1: Under the Hood of C++ Programming

In this section, the reader will learn the details of C++ program compilation and linking, and dive into the details of Object-Oriented Programming (OOP), templates, and memory management.
This section comprises the following chapters:
  • Chapter 1, Introduction to Building C++ Applications
  • Chapter 2, Low-Level Programming with C++
  • Chapter 3, Details of Object-Oriented Programming
  • Chapter 4, Understanding and Designing Templates
  • Chapter 5, Memory Management and Smart Pointers

Introduction to Building C++ Applications

Programming languages differ by their program execution model; the most common are interpreted and compiled languages. Compilers translate source code into machine code, which a computer can run without intermediary support systems. Interpreted language code, on the other hand, requires support systems, interpreters, and the virtual environment to work.
C++ is a compiled language, which makes programs run faster than their interpreted counterparts. While C++ programs should be compiled for each platform, interpreted programs can operate cross-platform.
We are going to discuss the details of a program-building process, starting with the phases of processing the source code – done by the compiler- and ending with the details of the executable file (the compiler's output). We will also learn why a program built for one platform won't run on another one.
The following topics will be covered in this chapter:
  • Introduction to C++20
  • Details of the C++ preprocessor
  • Under the hood of the source code compilation
  • Understanding the linker and its functionality
  • The process of loading and running an executable file

Technical requirements

The g++ compiler with the option -std=c++2a is used to compile the examples throughout the chapter. You can find the source files used in this chapter at https://github.com/PacktPublishing/Expert-CPP .

Introduction to C++20

C++ has evolved over the years and now it has a brand-new version, C++20. Since C++11, the C++ standard has grown the language feature set tremendously. Let's look at notable features in the new C++20 standard.

Concepts

Concepts are a major feature in C++20 that provides a set of requirements for types. The basic idea behind concepts is the compile-time validation of template arguments. For example, to specify that the template argument must have a default constructor, we use the default_constructible concept in the following way:
template <default_constructible T>
void make_T() { return T(); }
In the preceding code, we missed the typename keyword. Instead, we set a concept that describes the T parameter of the template function.
We can say that concepts are types that describe other types – meta-types, so to speak. They allow the compile-time validation of template parameters along with a function invocation based on type properties. We will discuss concepts in detail in Chapter 3, Details of Object-Oriented Programming, and Chapter 4, Understanding and Designing Templates.

Coroutines

Coroutines are special functions able to stop at any defined point of execution and resume later. Coroutines extend the language with the following new keywords:
  • co_await suspends the execution of the coroutine.
  • co_yield suspends the execution of the coroutine while also returning a value.
  • co_return is similar to the regular return keyword; it finishes the coroutine and returns a value. Take a look at the following classic example:
generator<int> step_by_step(int n = 0) {
while (true) {
co_yield n++;
}
}
A coroutine is associated with a promise object. The promise object stores and alerts the state of the coroutine. We will dive deeper into coroutines in Chapter 8, Concurrency and Multithreading.

Ranges

The ranges library provides a new way of working with ranges of elements. To use them, you should include the <ranges> header file. Let's look at ranges with an example. A range is a sequence of elements having a beginning and an end. It provides a begin iterator and an end sentinel. Consider the following vector of integers:
import <vector>

int main()
{
std::vector<int> elements{0, 1, 2, 3, 4, 5, 6};
}
Ranges accompanied by range adapters (the | operator) provide powerful functionality to deal with a range of elements. For example, examine the following code:
import <vector>
import <ranges>

int main()
{
std::vector<int> elements{0, 1, 2, 3, 4, 5, 6};
for (int current : elements | ranges::view::filter([](int e) { return
e % 2 == 0; })
)
{
std::cout << current << " ";
}
}
In the preceding code, we filtered the range for even integers using ranges::view::filter(). Pay attention to the range adapter | applied to the elements vector. We will discuss ranges and their powerful features in Chapter 7, Functional Programming.

More C++20 features

C++20 is a new big release of the C++ language. It contains many features that make the language more complex and flexible. Concepts, ranges, and coroutines are some of the many features that will be discussed throughout the book.
One of the most anticipated features is modules, which provide the ability to declare modules and export types and values within those modules. You can consider modules an improved version of header files with the now redundant include-guards. We'll cover C++20 modules in this chapter.
Besides notable features added in C++20, there is a list of other features that we will discuss throughout the book:
  • The spaceship operator: operator<=>(). The verbosity of operator overloading can now be controlled by leveraging operator<=&g...

Inhaltsverzeichnis