Roadmap Start learning
E12AdvancedElectiveHard
Advanced C++
Templates in depth, concepts, constexpr, the object model and undefined behaviour.
1.6 h of lessons~0 min of practice across 0 problems
Prerequisites not done
Lessons0 / 5 lessons
Mastery · target 80%0 / 0 solved
Completing the lessons finishes the module. Mastery also needs 80% of its problems solved.
What you will be able to do
- Write generic code with templates and concepts
- Move work to compile time with constexpr
- Explain the C++ object model, vtables and object layout
- Recognise undefined behaviour and the bugs it causes
Before you start
Prerequisites: this module uses their material directly.
Lessons
1.Templates in DepthHow the compiler deduces template arguments, forwarding references and std::forward, variadic templates and fold expressions, SFINAE and why concepts replaced it, and CRTP for static polymorphism.20m2.ConceptsDefine concepts with requires-expressions, constrain overloads and member functions, understand how subsumption orders overloads (and when it silently does not), use the standard concepts, and read the much shorter error messages.18m3.constexpr in DepthExactly when the compiler must evaluate code, what C++20 allows inside constant evaluation, is_constant_evaluated and its pitfalls, consteval validation, constinit, compile-time std::vector, and lookup tables proved correct with static_assert.18m4.The Object ModelHow objects are laid out in memory: alignment and padding with real printed sizes, the empty base optimisation, the vptr and vtable as Clang builds them, the costs of multiple and virtual inheritance, and when memcpy on an object is legal.20m5.Undefined BehaviourWhat undefined behaviour means to an optimiser, demonstrated with real -O2 programs (an overflow check deleted, an out-of-bounds loop turned into return true, a never-called function called), plus strict aliasing, uninitialised reads, lifetime bugs, data races and the tools that catch them.20m
Where this module fits
- Quant Developer: Optional; recommended for Low-Latency C++