Skip to content
academia.sh

Course Advanced

Templates and Performance

Published Updated

By the end of this course

Start course

01

Template Metaprogramming

Function and class templates, specialization, variadic template parameters, type traits, overload resolution and SFINAE, static polymorphism — each paired with the question of where the cost moved.

  1. 01 Function and Class Templates Function templates, template argument deduction, explicit template arguments and class templates; the compiler writing a new body for every new type, and that cost moving to compile time.
  2. 02 Template Specialization Full and partial specialization, the primary template, selection of the most specialized match, the memory layout of the bool pack, and the cost that reading from a bit leaves to run time.
  3. 03 Variadic Templates Parameter packs, sizeof..., pack expansion, comparing recursive expansion with fold expressions, forwarding with std::forward, and how many bodies the expansion method makes the compiler write.
  4. 04 Type Traits Standard type traits, selection at compile time with if constexpr, static_assert, writing your own type trait, and the selection leaving zero queries at run time.
  5. 05 Overload Resolution and SFINAE Candidates and viable candidates, the contest between a template and a non-template function, candidate elimination with enable_if_t, detection with void_t, and constraints with C++20 concepts.
  6. 06 Static Polymorphism Dispatch at compile time with CRTP, the contrast with the virtual function version, policy classes and mixins, a static interface constrained by a concept, and selection returning to run time with variant.

02

Concurrency and Performance

Threads and locks, the memory model, cache-friendly data layout, profiling and benchmarking, managing compile times, package management and build tools — each paired with the question of where the cost moved.

  1. 01 Threads and Locks std::thread and join, std::jthread, std::mutex with std::lock_guard, std::scoped_lock, std::unique_lock with std::condition_variable, a producer/consumer queue, and counting how many synchronization points a lock adds.
  2. 02 The Memory Model std::atomic, read-modify-write operations, the seq_cst, acquire, release and relaxed memory orders, the happens-before relation, and counting how many synchronization points a release/acquire publish asks for.
  3. 03 Cache-Friendly Data Layout The cache line, spatial and temporal locality, array of structures versus structure of arrays, row order and column order, false sharing, and counting how many non-contiguous jumps a data layout leaves.
  4. 04 Profiling and Benchmarking Instrumentation versus sampling, finding the hot spot by placing counters, the warm-up, repetition and dead code rules of benchmarking, and how the place where a measurement starts changes the result.
  5. 05 Managing Compile Times Forward declaration, trimming unnecessary includes, the pimpl idiom, opaque types, explicit instantiation and extern template, and how the cost gained at compile time moves to run time per object.
  6. 06 Package Management and Build Tools Reproducible installation with a dependency table, version pinning and a lock file; how a header-only template library rebuilds every unit.

Final exam

Templates and Performance — Final Exam

In preparation

This course's question bank is not complete yet. The exam opens here automatically once enough questions are added.

Start typing to search.

↑↓ ↵ Esc navigate · open · close