Title Page - Courses Copyright and Credits - Courses Expert C++ Programming Packt Upsell - Courses Why subscribe? PacktPub.com Preface Who this learning path is for What this learning path covers To get the most out of this learning path Download the example code files Conventions used Get in touch Reviews Mastering C++ Programming Introduction to C++17 Standard Template Library The Standard Template Library architecture Algorithms Iterators Containers Functors Sequence containers Array Code walkthrough Commonly used APIs in an array Vector  Code walkthrough Commonly used vector APIs Code walkthrough Pitfalls of a vector List  Commonly used APIs in a list Forward list Code walkthrough Commonly used APIs in a forward_list container Deque Commonly used APIs in a deque Associative containers Set Code walkthrough Commonly used APIs in a set Map Code walkthrough Commonly used APIs in a map Multiset Multimap Unordered sets Unordered maps Unordered multisets Unordered multimaps Container adapters Stack Commonly used APIs in a stack Queue Commonly used APIs in a queue Priority queue Commonly used APIs in a priority queue Summary Template Programming Generic programming Function templates Code walkthrough Overloading function templates Code walkthrough Class template Code walkthrough Explicit class specializations Code walkthrough Partial template specialization Summary Smart Pointers Memory management Issues with raw pointers Smart pointers auto_ptr Code walkthrough - Part 1 Code walkthrough - Part 2 unique_ptr Code walkthrough shared_ptr Code walkthrough weak_ptr Circular dependency Summary Developing GUI Applications in C++ Qt  Installing Qt 5.7.0 in Ubuntu 16.04 Qt Core Writing our first Qt console application Qt Widgets Writing our first Qt GUI application Layouts Writing a GUI application with a horizontal layout Writing a GUI application with a vertical layout Writing a GUI application with a box layout Writing a GUI application with a grid layout Signals and slots Using stacked layout in Qt applications Writing a simple math application combining multiple layouts Summary Test-Driven Development TDD Common myths and questions around TDD Does it take more efforts for a developer to write a unit test?  Is code coverage metrics good or bad? Does TDD work for complex legacy projects?  Is TDD even applicable for embedded or products that involve hardware? Unit testing frameworks for C++ Google test framework Installing Google test framework on Ubuntu How to build google test and mock together as one single static library without installing? Writing our first test case using the Google test framework Using Google test framework in Visual Studio IDE TDD in action Testing a piece of legacy code that has dependency Summary Behavior-Driven Development Behavior-driven development TDD versus BDD C++ BDD frameworks The Gherkin language Installing cucumber-cpp in Ubuntu Installing the cucumber-cpp framework prerequisite software Building and executing the test cases Feature file Spoken languages supported by Gherkin The recommended cucumber-cpp project folder structure Writing our first Cucumber test case Integrating our project in cucumber-cpp CMakeLists.txt Executing our test case Dry running your cucumber test cases BDD - a test-first development approach Let's build and run our BDD test case It's testing time! Summary Code Smells and Clean Code Practices Code refactoring Code smell What is agile? SOLID design principle Single responsibility principle Open closed principle Liskov substitution principle Interface segregation Dependency inversion Code smell Comment smell Long method Long parameter list Duplicate code Conditional complexity Large class Dead code Primitive obsession Data class Feature envy Summary Mastering C++ Multithreading Revisiting Multithreading Getting started The multithreaded application Makefile Other applications Summary Multithreading Implementation on the Processor and OS Introduction to POSIX pthreads Creating threads with the pthreads library How to compile and run Does C++ support threads natively? Defining processes and threads Tasks in x86 (32-bit and 64-bit) Process state in ARM The stack Defining multithreading Flynn's taxonomy Symmetric versus asymmetric multiprocessing Loosely and tightly coupled multiprocessing Combining multiprocessing with multithreading Multithreading types Temporal multithreading Simultaneous multithreading (SMT) Schedulers Tracing the demo application Mutual exclusion implementations Hardware Software Concurrency How to compile and run Asynchronous message passing using the concurrency support library How to compile and run Concurrency tasks How to compile and run Using tasks with a thread support library How to compile and run Binding the thread procedure and its input to packaged_task  How to compile and run Exception handling with the concurrency library How to compile and run What did you learn? Summary C++ Multithreading APIs API overview POSIX threads Windows support PThreads thread management Mutexes Condition variables Synchronization Semaphores Thread local storage (TLC) Windows threads Thread management Advanced management Synchronization Condition variables Thread local storage Boost Thread class Thread pool Thread local storage (TLS) Synchronization C++ threads Putting it together Summary Thread Synchronization and Communication Safety first The scheduler High-level view Implementation Request class Worker class Dispatcher Makefile Output Sharing data Using r/w-locks Using shared pointers Summary Native C++ Threads and Primitives The STL threading API Boost.Thread API The 2011 standard C++14 Thread class Basic use Passing parameters Return value Moving threads Thread ID Sleeping Yield Detach Swap Mutex Basic use Non-blocking locking Timed mutex Lock guard Unique lock Scoped lock Recursive mutex Recursive timed mutex Shared mutex Shared timed mutex Condition variable Condition_variable_any Notify all at thread exit Future Promise Shared future Packaged_task Async Launch policy Atomics Summary Debugging Multithreaded Code When to start debugging The humble debugger GDB Debugging multithreaded code Breakpoints Back traces Dynamic analysis tools Limitations Alternatives Memcheck Basic use Error types Illegal read / illegal write errors Use of uninitialized values Uninitialized or unaddressable system call values Illegal frees Mismatched deallocation Overlapping source and destination Fishy argument values Memory leak detection Helgrind Basic use Misuse of the pthreads API Lock order problems Data races DRD Basic use Features C++11 threads support Summary Best Practices Proper multithreading Wrongful expectations - deadlocks Being careless - data races Mutexes aren't magic Locks are fancy mutexes Threads versus the future Static order of initialization Summary Atomic Operations - Working with the Hardware Atomic operations Visual C++ GCC Memory order Other compilers C++11 atomics Example Non-class functions Example Atomic flag Memory order Relaxed ordering Release-acquire ordering Release-consume ordering Sequentially-consistent ordering Volatile keyword Summary Multithreading with Distributed Computing Distributed computing, in a nutshell MPI Implementations Using MPI Compiling MPI applications The cluster hardware Installing Open MPI Linux and BSDs Windows Distributing jobs across nodes Setting up an MPI node Creating the MPI host file Running the job Using a cluster scheduler MPI communication MPI data types Custom types Basic communication Advanced communication Broadcasting Scattering and gathering MPI versus threads Potential issues Summary Multithreading with GPGPU The GPGPU processing model Implementations OpenCL Common OpenCL applications OpenCL versions OpenCL 1.0 OpenCL 1.1 OpenCL 1.2 OpenCL 2.0 OpenCL 2.1 OpenCL 2.2 Setting up a development environment Linux Windows OS X/MacOS A basic OpenCL application GPU memory management GPGPU and multithreading Latency Potential issues Debugging GPGPU applications Summary C++17 STL Cookbook The New C++17 Features Introduction Using structured bindings to unpack bundled return values How to do it... How it works... There's more... Limiting variable scopes to if and switch statements How to do it... How it works... There's more... Profiting from the new bracket initializer rules How to do it... How it works... Letting the constructor automatically deduce the resulting template class type How to do it... How it works... There's more... Simplifying compile time decisions with constexpr-if How to do it... How it works... There's more... Enabling header-only libraries with inline variables How it's done... How it works... There's more... Implementing handy helper functions with fold expressions How to do it... How it works... There's more... Match ranges against individual items Check if multiple insertions into a set are successful Check if all the parameters are within a certain range Pushing multiple items into a vector STL Containers Using the erase-remove idiom on std::vector How to do it... How it works... There's more... Deleting items from an unsorted std::vector in O(1) time How to do it... How it works... Accessing std::vector instances the fast or the safe way How to do it... How it works... There's more... Keeping std::vector instances sorted How to do it... How it works... There's more... Inserting items efficiently and conditionally into std::map How to do it... How it works... There's more... Knowing the new insertion hint semantics of std::map::insert How to do it... How it works... There's more... Efficiently modifying the keys of std::map items How to do it... How it works... There's more... Using std::unordered_map with custom types How to do it... How it works... Filtering duplicates from user input and printing them in alphabetical order with std::set How to do it... How it works... std::istream_iterator std::inserter Putting it together Implementing a simple RPN calculator with std::stack How to do it... How it works... Stack handling Distinguishing operands from operations from user input Selecting and applying the right mathematical operation There's more... Implementing a word frequency counter with std::map How to do it... How it works... Implement a writing style helper tool for finding very long sentences in text with std::multimap How to do it... How it works...  There's more... Implementing a personal to-do list using std::priority_queue How to do it... How it works... Iterators Introduction Iterator categories Input iterator Forward iterator Bidirectional iterator Random access iterator Contiguous iterator Output iterator Mutable iterator Building your own iterable range How to do it... How it works... Making your own iterators compatible with STL iterator categories How to do it... How it works... There's more... Using iterator adapters to fill generic data structures How to do it... How it works... std::back_insert_iterator std::front_insert_iterator std::insert_iterator std::istream_iterator std::ostream_iterator Implementing algorithms in terms of iterators How to do it... There's more... Iterating the other way around using reverse iterator adapters How to do it... How it works... Terminating iterations over ranges with iterator sentinels How to do it... Automatically checking iterator code with checked iterators How to do it... How it works... There's more... Building your own zip iterator adapter How to do it... There's more... Ranges library Lambda Expressions Introduction Defining functions on the run using lambda expressions How to do it... How it works... Capture list mutable (optional) constexpr (optional) exception attr (optional) return type (optional) Adding polymorphy by wrapping lambdas into std::function How to do it... How it works... Composing functions by concatenation How to do it... How it works... Creating complex predicates with logical conjunction How to do it... There's more... Calling multiple functions with the same input How to do it... How it works... Implementing transform_if using std::accumulate and lambdas How to do it... How it works... Generating cartesian product pairs of any input at compile time How to do it... How it works... STL Algorithm Basics Introduction Copying items from containers to other containers How to do it... How it works... Sorting containers How to do it... How it works... Removing specific items from containers How to do it... How it works... Transforming the contents of containers How to do it... How it works... Finding items in ordered and unordered vectors How to do it... How it works... Limiting the values of a vector to a specific numeric range with std::clamp How to do it... How it works... Locating patterns in strings with std::search and choosing the optimal implementation How to do it... How it works... Sampling large vectors How to do it... How it works... Generating permutations of input sequences How to do it... How it works... Implementing a dictionary merging tool How to do it... How it works... Advanced Use of STL Algorithms Introduction Implementing a trie class using STL algorithms How to do it... How it works... Implementing a search input suggestion generator with tries How to do it... How it works... There's more... Implementing the Fourier transform formula with STL numeric algorithms How to do it... How it works... Calculating the error sum of two vectors How to do it... How it works... Implementing an ASCII Mandelbrot renderer How to do it... How it works... Building our own algorithm - split How to do it... How it works... There's more... Composing useful algorithms from standard algorithms - gather How to do it... How it works... Removing consecutive whitespace between words How to do it... How it works... Compressing and decompressing strings How to do it... How it works... There's more... Strings, Stream Classes, and Regular Expressions Introduction Creating, concatenating, and transforming strings How to do it... How it works... Trimming whitespace from the beginning and end of strings How to do it... How it works... Getting the comfort of std::string without the cost of constructing std::string objects How to do it... How it works... Reading values from user input How to do it... How it works... Counting all words in a file How to do it... How it works... Formatting your output with I/O stream manipulators How to do it... How it works... Initializing complex objects from file input How to do it... How it works... Filling containers from std::istream iterators How to do it... How it works... Generic printing with std::ostream iterators How to do it... How it works... Redirecting output to files for specific code sections How to do it... How it works... Creating custom string classes by inheriting from std::char_traits How to do it... How it works... Tokenizing input with the regular expression library How to do it... How it works... Comfortably pretty printing numbers differently per context on the fly How to do it... Catching readable exceptions from std::iostream errors How to do it... How it works... Utility Classes Introduction Converting between different time units using std::ratio How to do it... How it works... There's more... Converting between absolute and relative times with std::chrono How to do it... How it works... Safely signalizing failure with std::optional How to do it... How it works... Applying functions on tuples How to do it... How it works... Quickly composing data structures with std::tuple How to do it... How it works... operator<< for tuples The zip function for tuples Replacing void* with std::any for more type safety How to do it... How it works... Storing different types with std::variant How to do it... How it works... Automatically handling resources with std::unique_ptr How to do it... How it works... Automatically handling shared heap memory with std::shared_ptr How to do it... How it works... There's more... Dealing with weak pointers to shared objects How to do it... How it works... Simplifying resource handling of legacy APIs with smart pointers How to do it... How it works... Sharing different member values of the same object How to do it... How it works... Generating random numbers and choosing the right random number engine How to do it... How it works... Generating random numbers and letting the STL shape specific distributions How to do it... How it works... Parallelism and Concurrency Introduction Automatically parallelizing code that uses standard algorithms How to do it... How it works... Which STL algorithms can we parallelize this way? How do those execution policies work? What does vectorization mean? Putting a program to sleep for specific amounts of time How to do it... How it works... Starting and stopping threads How to do it... How it works... Performing exception safe shared locking with std::unique_lock and std::shared_lock How to do it... How it works... Mutex classes Lock classes Avoiding deadlocks with std::scoped_lock How to do it... How it works... Synchronizing concurrent std::cout use How to do it... How it works... Safely postponing initialization with std::call_once How to do it... How it works... Pushing the execution of tasks into the background using std::async How to do it... How it works... There's more... Implementing the producer/consumer idiom with std::condition_variable How to do it... How it works... Implementing the multiple producers/consumers idiom with std::condition_variable How to do it... How it works... Parallelizing the ASCII Mandelbrot renderer using std::async How to do it... How it works... Implementing a tiny automatic parallelization library with std::future How to do it... How it works... Filesystem Introduction Implementing a path normalizer How to do it... How it works... There's more... Getting canonical file paths from relative paths How to do it... How it works... Listing all files in directories How to do it... How it works... Implementing a grep-like text search tool How to do it... How it works... There's more... Implementing an automatic file renamer How to do it... Implementing a disk usage counter How to do it... How it works... Calculating statistics about file types How to do it... Implementing a tool that reduces folder size by substituting duplicates with symlinks How to do it... How it works... There's more... Bibliography