This textbook is on C++, a general-purpose programming language. It describes various language constructs and modern versions of the language and includes many examples in the form of code listings. It gives tips for writing efficient and good code. It also provides some details on the C++ standard library and introduces build processes for C++ programs.
The preface motivates readers to learn C++ by explaining why lots of infrastructure code is written in C++. It compares C++ with other programming languages, including C, Python, and Java. Chapter 1 introduces the C++ language, including expressions, statements, and functions: expressions with variables, constants, literals, operators, and function calls; various types of statements, such as assignments, conditionals, and loops; and declaration of functions, parameters in functions, variable scopes, overloading of functions, and so on. Additionally, exception handling, preprocessor macros, and comments are introduced.
The second chapter covers class members. Fields, methods, and their accesses are introduced. Details include constructors, destructors, copies, moves, and operator overloading. Resource management with respect to these constructs are described. Furthermore, the chapter looks at member variables and their initialization, static members, ways of accessing members, and friends. The third chapter is on generic programming. Templates for classes, functions, variables, and variadic templates are described in detail. Related features such as concepts, functors, namespaces, automatic type inferences, lambdas, and so on are also covered.
Chapter 4 is on libraries, with sections on the Standard Template Library (STL), numerics, and concurrency. The description of STL includes containers, iterators, algorithms, and parallelism. The description of numerics includes random number generation facilities, distributions, type traits, complex number computations, and other mathematical utilities. The chapter’s description of concurrency includes some techniques using threads and locks. The last section of the chapter has a list of various third-party libraries, mainly from scientific application domains.
Chapter 5 is on techniques for writing efficient code. Specializations can be achieved by using constants, constant expressions, template expressions, and so on. A separate section on loop unrolling is given, because unrolling helps compilers in parallelizations. The chapter also has a section on how algebras can be expressed in C++ using concept constructs.
The sixth chapter begins by explaining some principles of object-oriented programming. It instructs readers on how to achieve them in the language. It also has a detailed section on castings. The last chapter describes how to solve ordinary partial differential equations with the Runge-Kutta method using C++. It also covers the standard build process and build tools for C++ projects and describes modules in detail.
Appendix A extends all the topics to give useful tips for good programming. Appendix B describes debuggers, memory analysis tools, and some common commands. Appendix C is a quick look at language definitions.
Discovering modern C++ can be used as textbook for any type of course on C++. Sections are marked based on language versions (such as C++11, C++14, C++17, and C++20). Every chapter has exercises. Readers who already have some knowledge of programming will easily understand the code listings. The book also includes a list of references.