35,99 €
Solve complex problems in C++ by learning how to think like a computer scientist. This book introduces computational thinking—a framework for solving problems using decomposition, abstraction, and pattern recognition—and shows you how to apply it using modern C++ features. You'll learn how to break down challenges, choose the right abstractions, and build solutions that are both maintainable and efficient.
Through small examples and a large case study, this book guides you from foundational concepts to high-performance applications. You’ll explore reusable templates, algorithms, modularity, and even parallel computing and GPU acceleration. With each chapter, you’ll not only expand your C++ skillset, but also refine the way you approach and solve real-world problems.
Written by a seasoned research engineer and C++ developer, this book combines practical insight with academic rigor. Whether you're designing algorithms or profiling production code, this book helps you deliver elegant, effective solutions with confidence.
Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:
Seitenzahl: 596
Veröffentlichungsjahr: 2025
The C++ Programmer’s Mindset
Learn computational, algorithmic, and systems thinking to become a better C++ programmer
Sam Morley
The C++ Programmer’s Mindset
Copyright © 2025 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing or its dealers and distributors, will be held liable for any damages caused or alleged to have been caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
Portfolio Director: Kunal Chaudhari
Relationship Lead: Dhruv J. Kataria
Project Manager: K. Loganathan
Content Engineer: Deepayan Bhattacharjee
Technical Editor: Irfa Ansari
Copy Editor: Safis Editing
Indexer: Tejal Soni
Proofreader: Deepayan Bhattacharjee
Production Designer: Ajay Patule
Growth Lead: Mansi Shah
First published: November 2025
Production reference: 1141125
Published by Packt Publishing Ltd.
Grosvenor House
11 St Paul’s Square
Birmingham
B3 1RB, UK.
ISBN 978-1-83588-842-1
www.packtpub.com
To Saba
Sam Morley is a research software engineer and mathematician at the University of Oxford, where he works on the DataSig project. He is the lead developer of the RoughPy library for computational rough paths in the data science of streamed data, and several other high-performance accelerator libraries in C++ and CUDA. Sam is a former lecturer in mathematics and author of Applying Math with Python. He greatly enjoys logical puzzles and is often found pondering fiendish Sudoku puzzles.
I want to thank my friends and colleagues at the University of Oxford, the broader DataSig team, and my friends from the Alan Turing Institute. I’d also like to thank my family, especially my parents, who’ve been very supportive throughout.
Alexei Kondratiev is a mission-critical software and embedded systems engineer with 20+ years of experience in Medical, Automotive, Advanced Driver Assistance Systems (ADAS), and Aerospace, low-latency and high-throughput concurrent and asynchronous C++ software development. He has a solid background in network programming and protocols, distributed systems, system and embedded programming, troubleshooting, integration with open-source projects, performance analysis, and optimization.
He is a C++ software developer at LTA Research, an aerospace research and development company that builds experimental and certified manned airships.
At LTA, he is an owner of the Soft Real-Time Embedded Linux Airship Helium Gas Cells Volume Monitoring System, Soft Real-Time Hardware Simulation System, and Soft Real-Time Dynon Avionics SkyView HDX Emulator of the Glass Cockpit Electronic Flight Instrument System R&D C++ projects.
Julian Faber has more than 30 years’ experience of software design and development with C++, working for some of the largest investment banks in the world. Deeply passionate about creativity within software engineering, his focus these days is latency sensitivity on trading systems and enhancing usability. A hallmark of his work is designing systems to be fully testable, as he is a keen advocate for complete testing of software.
To join the Discord community for this book - where you can share feedback, ask questions to the author, and learn about new releases - follow the QR code below:
https://packt.link/deep-engineering-cpp
Solving problems is a large part of writing code. Sometimes these are small problems that we barely acknowledge and sometimes they are grand challenges that seem insurmountable at first. Whatever domain you work in, and whatever the problem, solving problems is an iterative process with false starts and dead ends until you eventually find the “right” path – this is normal. After solving a few big problems, you’ll start to recognize some common features in this process: breaking the problem down into smaller pieces, formulating or finding good abstractions, recognizing patterns that appear in other kinds of problems, and formulating a list of steps to follow to construct solutions to the problem. In computer science, this framework for solving problems is called computational thinking.
Of course, formulating abstract solutions and algorithms is only part of actually solving the problem. The other part is actually realizing the solution as software and delivering it, whatever form that might take. This means you must first select the right tool to build this software, which includes selecting the programming language to use. Sometimes this choice is made for you, but other times, the choice depends on many factors. When performance is paramount, C++ is an obvious choice.
Modern C++ is very powerful and comes with a large ecosystem of high-performance libraries. Many substantial updates in the past decade have brought C++ into the modern era of programming languages. More than anything, what C++ provides is control. Other languages can achieve performance in some places, but they often fall down in other areas. Few languages deliver the same performance as C++ without sacrificing control, flexibility, or ease of use.
Being proficient at solving problems in C++, of course, requires you to have a good knowledge of C++ and standard techniques. Delivering the right balance of performance and flexibility often also requires an understanding of the broader context in which the code will run: the operating system, hardware, processor features, and specific accelerator hardware.
Having all this in mind when choosing data structures and designing algorithms can give you the edge. But it’s more than that. Understanding these concepts will also help you select good abstractions and identify useful patterns more easily. The connection between C++ and problem-solving is two-way, and that is the topic of this book.
This book is for people who are already familiar with the basics of C++ programming who are looking to become better at solving complex problems. No background in theoretical computer science is assumed; where this does appear, we keep it light on detail and give references to textbooks that explain it more.
This is not a step-by-step guide for solving problems. Instead, it is a discussion about the interplay between the C++ language, features, and facilities, and the computational thinking framework. We explain the context surrounding working in C++ that you should keep in mind and how this relates to the problem-solving process.
Chapter 1, Thinking Computationally, introduces the computational thinking framework for solving problems. We discuss the different components of computational thinking and how these might manifest in the problem-solving process. We also discuss a few features of modern C++ and good coding practices that will be used throughout the book.
Chapter 2, Abstraction in Detail, goes into more detail about abstraction. Specifically, we look at the abstraction mechanisms in C++ and how these can help us find useful abstractions in the data or methodology of the problem we’re solving.
Chapter 3, Algorithmic Thinking and Complexity, talks about the design and analysis of algorithms. We discuss computational complexity and the different kinds of algorithms, and some design characteristics of different kinds of algorithms you can use when designing your own algorithms.
Chapter 4, Understanding the Machine, discusses modern computer hardware and operating systems and how understanding these can help us write code that runs faster (even if we can’t reduce the complexity).
Chapter 5, Data Structures, discusses different data structures and their characteristics. We discuss different patterns of memory usage and how these impact performance in practice.
Chapter 6, Reusing Your Code and Modularity, considers the different mechanisms for making your code reusable and modular using the mechanisms in C++: functions, classes, namespaces, and so on. We also discuss packaging entire compiled components as libraries.
Chapter 7, Outlining the Challenge, describes a large challenge that we will solve over the course of the next five chapters. This includes using the principles of computational thinking to find a strategy for how to tackle the challenge as a whole.
Chapter 8, Building a Simple Command-Line Interface, is the first chapter of our big challenge. Here we design a simple command-line interface that will allow us and the end user to interact with our eventual solution to the problem.
Chapter 9, Reading Data from Different Formats, is the second chapter in our big challenge. We discuss the problem of ingesting data from two different common formats and designing the internal interfaces that allow us to hide the implementation details.
Chapter 10, Finding Information in Text, is the third chapter in our big challenge. It covers searching free-form text for specific patterns using regular expressions.
Chapter 11, Clustering Data, is the fourth chapter in our big challenge. We implement a k-means clustering algorithm to reduce our large, messy dataset to a small number of representative points.
Chapter 12, Reflecting on What We Have Built, is the final chapter in our big challenge. We add the finishing touches to the program and run it on some sample data. We look back over what we built in the previous four chapters and reflect on what worked well and what didn’t work so well.
Chapter 13, The Problems of Scale, looks at how we might scale up our computations to deal with large, computationally intensive problems that require multiple threads, multiple processes, or even multiple computers.
Chapter 14, Dealing with GPUs and Specialized Hardware, looks at different means of interacting with specialized accelerator hardware for specific tasks. We look at OpenMP device offload, CUDA programming for Nvidia GPUs, and SYCL programming.
Chapter 15, Profiling Your Code, is where we examine our code through a profiler to see where our code is spending its time and how we might use this information to make our code faster.
In this book, we assume that you have at least a basic knowledge of C++ programming and are familiar with the syntax and features of the language, and know how to use the CMake build system generator on your operating system of choice.
Most of the code samples in this book are written in standards-compliant C++, so it should work on any platform that provides a C++ compiler that supports at least C++20 (some chapters also require C++23). Some code fragments will only work on X86(-64) hardware, especially in Chapter 4, but the build system will simply not build these targets on other architectures (sorry ARM users).
Software/hardware covered in the book
Operating system requirements
C++20 (and C++23 in some places)
Windows, macOS, or Linux
CMake 3.30+
Each folder in the GitHub repository for this book has a separate CMakeLists.txt file. These are independent of each other. In some of the folders, we need additional dependencies. These are either acquired automatically using the CMake FetchContent functions or findable with CMake find_package. For these, we also provide a vcpkg manifest file to download and build the missing dependencies.
If you are using the digital version of this book, we advise you to type the code yourself or access the code from the book’s GitHub repository (a link is available in the next section). Doing so will help you avoid any potential errors related to the copying and pasting of code.
The code bundle for the book is hosted on GitHub at https://github.com/PacktPublishing/The-CPP-Programmers-Mindset. We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing. Check them out!
We also provide a PDF file that has color images of the screenshots/diagrams used in this book. You can download it here: https://packt.link/gbp/9781835888421.
There are a number of text conventions used throughout this book.
CodeInText: Indicates code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter/X handles. For example: “This function just calls std::signal, as follows.”
A block of code is set as follows:
voidsetup_signals(){ std::signal(SIGINT, &sigint_handler); }Any command-line input or output is written as follows:
cmake -B build -S . -GNinja -DCMAKE_BUILD_TYPE=Release cmake --build build --config=ReleaseBold: Indicates a new term, an important word, or words that you see on the screen. For instance, words in menus or dialog boxes appear in the text like this. For example: “Sometimes, large language model (LLM)-based coding assistants can be a great help.”
Warnings or important notes appear like this.
Tips and tricks appear like this.
Feedback from our readers is always welcome.
General feedback: If you have questions about any aspect of this book or have any general feedback, please email us at [email protected] and mention the book’s title in the subject of your message.
Errata: Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you have found a mistake in this book, we would be grateful if you reported this to us. Please visit http://www.packt.com/submit-errata, click Submit Errata, and fill in the form.
Piracy: If you come across any illegal copies of our works in any form on the internet, we would be grateful if you would provide us with the location address or website name. Please contact us at [email protected] with a link to the material.
If you are interested in becoming an author: If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, please visit http://authors.packt.com/.
Once you’ve read The C++ Programmer’s Mindset, we’d love to hear your thoughts! Please click here to go straight to the Amazon review page for this book and share your feedback.
Your review is important to us and the tech community and will help us make sure we’re delivering excellent quality content.
This book comes with free benefits to support your learning. Activate them now for instant access (see the “How to Unlock” section for instructions).
Here’s a quick overview of what you can instantly unlock with your purchase:
PDF and ePub Copies
Next-Gen Web-Based Reader
Access a DRM-free PDF copy of this book to read anywhere, on any device.
Multi-device progress sync: Pick up where you left off, on any device.
Use a DRM-free ePub version with your favorite e-reader.
Highlighting and notetaking: Capture ideas and turn reading into lasting knowledge.
Bookmarking: Save and revisit key sections whenever you need them.
Dark mode: Reduce eye strain by switching to dark or sepia themes.
Scan the QR code (or go to packtpub.com/unlock). Search for this book by name, confirm the edition, and then follow the steps on the page.
Note: Keep your invoice handy. Purchases made directly from Packt don’t require one.
