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

Compartir libro
  1. 606 páginas
  2. English
  3. ePUB (apto para móviles)
  4. Disponible en iOS y Android
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

Detalles del libro
Vista previa del libro
Índice
Citas

Información del libro

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.

Preguntas frecuentes

¿Cómo cancelo mi suscripción?
Simplemente, dirígete a la sección ajustes de la cuenta y haz clic en «Cancelar suscripción». Así de sencillo. Después de cancelar tu suscripción, esta permanecerá activa el tiempo restante que hayas pagado. Obtén más información aquí.
¿Cómo descargo los libros?
Por el momento, todos nuestros libros ePub adaptables a dispositivos móviles se pueden descargar a través de la aplicación. La mayor parte de nuestros PDF también se puede descargar y ya estamos trabajando para que el resto también sea descargable. Obtén más información aquí.
¿En qué se diferencian los planes de precios?
Ambos planes te permiten acceder por completo a la biblioteca y a todas las funciones de Perlego. Las únicas diferencias son el precio y el período de suscripción: con el plan anual ahorrarás en torno a un 30 % en comparación con 12 meses de un plan mensual.
¿Qué es Perlego?
Somos un servicio de suscripción de libros de texto en línea que te permite acceder a toda una biblioteca en línea por menos de lo que cuesta un libro al mes. Con más de un millón de libros sobre más de 1000 categorías, ¡tenemos todo lo que necesitas! Obtén más información aquí.
¿Perlego ofrece la función de texto a voz?
Busca el símbolo de lectura en voz alta en tu próximo libro para ver si puedes escucharlo. La herramienta de lectura en voz alta lee el texto en voz alta por ti, resaltando el texto a medida que se lee. Puedes pausarla, acelerarla y ralentizarla. Obtén más información aquí.
¿Es Expert C++ un PDF/ePUB en línea?
Sí, puedes acceder a Expert C++ de Vardan Grigoryan, Shunguang Wu en formato PDF o ePUB, así como a otros libros populares de Computer Science y Programming in C++. Tenemos más de un millón de libros disponibles en nuestro catálogo para que explores.

Información

Año
2020
ISBN
9781838554767
Edición
1

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...

Índice