
Explain what a c++ idiom is as a language-specific, low-level way to solve problems. Differentiate idioms from patterns and preview future videos with concrete c++ idioms and examples.
explains the return type result idiom to implement a generic range function that builds a sequence container by deducing its type via a proxy range with conversion operators.
Understand how C++11's nullptr introduces a type-safe null pointer, eliminating overload ambiguities with 0 and enabling safe pointer and member-pointer conversions.
Explore type erasure in C++, comparing void pointers, templates, polymorphism, and unions, and weigh their safety, performance costs, and use cases.
Explore type erasure with std any, variant, and function, showing how any stores values of any type and how variant offers a safe union of listed types.
Demonstrates a basic any-like container that uses type erasure to store and retrieve values of different types, via a base pointer, inner type implementations, and type-specific static functions.
explain the curiously recurring template pattern (crtp) for static polymorphism in c++, showing how templates replace virtual functions with static downcasts and compile-time checks.
Explore the crtp to implement all relational operators for comparable classes from a single operator using static polymorphism and the C++20 spaceship operator.
Discover why C++ lacks virtual constructors and how polymorphic types enable creating or copying objects via a base pointer, using unique_ptr ownership and virtual mechanics to handle concrete types.
The virtual constructor idiom enables copying polymorphic objects at runtime without knowing their concrete types by defining two virtual methods, clone and create, that return a base pointer.
Pimpl stands for pointer to implementation, a private implementation technique that decouples library from user code, hides private data, and reduces compile-time dependencies.
Explore the pimpl idiom in c++ with forward declarations and unique_ptr, moving constructors and operators to the cpp, and examine compile and dependency implications.
Learn the fast pimpl approach using aligned storage and placement new to construct the implementation inside preallocated memory, avoiding heap allocation and pointer indirection while highlighting alignment and size checks.
Learn how substitution failure is not an error in C++ template overload resolution, where ill-formed substitutions are discarded from the overload set, enabling type traits and enable_if patterns.
Examine SFINAE in C++ by showing how substitution failures discard non-matching overloads, and how explicit template parameters and properties of some types guide overload resolution.
This lecture explains the enable-if idiom to constrain template overloads with type traits, demonstrates unsigned vs signed and base relationships, and guides implementing your own enable-if.
This lecture introduces the object generator idiom to create objects without explicit types, using a make-like function with templates, parameter packs, and perfect forwarding, aided by type deduction.
Learn the raii idiom: acquire resources on construction and release on destruction, aligning resource lifetime with the object to prevent leaks and ensure exception safety, using unique or shared ownership.
Explore RAII and resource acquisition is initialization by implementing a simple unique pointer that acquires a resource in the constructor and releases it in the destructor.
Continue implementing a unique pointer with move semantics, deleting copy operations, supporting move constructors and assignments, and exploring wrappers, factory returns, and perfect forwarding for resource transfer.
Master the reference counting idiom to safely share and release resources with a simplified shared pointer model. See how a shared state and a counter ensure proper destruction.
Learn the resource return idiom in C++, transfer ownership with unique_ptr in factory functions, prevent memory leaks, and use smart pointers for clear ownership.
small object optimization helps avoid dynamic allocations by using a stack buffer for small objects and heap for larger ones. it covers union data and placement new.
Every object must be at least one byte, enabling empty base optimization to avoid storage for empty bases. Policy-based design uses a template parameter to achieve zero memory overhead.
This course is about common C++ idioms that are related to:
- types system (return type resolver, type erasure, etc.)
- polymorphism (CRTP, virtual constructor)
- dependencies (PIMPL)
- templates (SFINE, enable-if, object generator)
- resource management (RAII, reference counting, resource return)
- optimization (SOO, EBO)
Idioms emerge from certain features of a programming language or a lack of them. Thus, learning C++ idioms helps better understand this language.
While learning those idioms, we will touch upon many parts of C++ like template parameters, including parameter pack, overload resolution, types of polymorphism, casting, conversion operators, placement new, special member functions, friend declarations, type deduction, etc.