
Source code
This lecture explains function pointers, static binding vs. dynamic binding, and how to obtain and use function addresses; it covers pointer syntax, signature matching, implicit calls, and runtime function switching.
Learn to pass function pointers as arguments, use aliases for pointer types, and replace conditionals with an array of function pointers for Getopt, faster than conditional statements, with assert-based debugging.
Explore how callbacks implement event handling and asynchronous execution using function pointers in C++, enabling inversion of control with the dependency inversion principle, plus plugin-like customization and loose coupling.
Learn how to use pointer to member functions in C++, including address syntax, invocation with objects or pointers, and differences with static member functions.
Revisit function pointers and callbacks by implementing a generic print operation for arrays and vectors using iterators and templates. Introduce function objects as a solution to signature limitations.
Compare function objects with functions to show state, parameterization, and compile-time binding. Discuss function pointers versus objects, covering serialization, type safety, inlining, and code size impacts on callbacks.
Explore converting function pointers to function objects and using lambda expressions to replace boilerplate, enable type conversion operators for stateful functors, and work with invoke in C++.
Explore lambda expressions in C++11 as concise function objects. Let the compiler generate an anonymous class with an overloaded operator(), capturing surrounding variables as a closure.
Explore the capture list in C++ lambda expressions, including capturing by value or reference, pack captures, and this pointer, plus stateful versus stateless lambdas with trailing return type.
Explore how C++ lambdas capture by reference and by value, avoid dangling references, and use internal lambdas to avoid polluting the global namespace and reduce code duplication.
Explore lambda captures with capture defaults and the store this technique, selectively capture by value or reference, and use variadic templates with fold expressions in c++11 through c++17.
Examine how local and class lambdas capture variables declared before them, including this and member variables. Global and thread local variables are implicitly accessible, and global lambdas lack capture lists.
explore how lambda expressions implement an immediately invoked function expression to create a private scope, prevent global namespace pollution, and perform one-time logic for initialization and constant setup.
Demonstrate rendering support links using a support type enum and a get support type function to show WhatsApp during working hours and email otherwise, with HTML rendering and constant considerations.
Use a lambda expression as an immediately invoked function expression to initialize a constant HTML object for WhatsApp or email, and prevent global namespace pollution.
Explore generic lambdas in c++14, where auto parameter types let lambdas act like function templates, boosting flexibility and reusability for algorithms on containers.
Explore generalized lambda capture to create new variables in the capture list. Capture moves, by value or by reference, and use mutable or const semantics in C++14 and beyond.
Demonstrates capturing by constant reference in lambdas with as const in c++17, applying the const qualifier to captured references and preventing modification, while discussing limitations with move-only types.
Examine lambda improvements in C++20, focusing on implicit capture of this, its deprecation with default capture, and the need to explicitly capture this to prevent undefined behavior.
Learn how consteval enables lambda expressions to be immediate functions that always execute at compile time, unlike constexpr lambdas, and understand capture expressions and the requirement for compile-time expressions.
explains how generic lambdas using auto create template closure types, obscuring parameter types and causing issues with mixed signedness and array decay; shows fixes with decltype, decay_t, and c++20 parameters.
Template type parameters in lambda expressions, introduced in c++20, let lambdas behave like function templates, work with argument and element types, and forward arguments for more powerful, reusable code.
Explore init-capture of pack expansion in lambda expressions with C++20. See how to create a new name for a pack using std::move and fold expressions.
Explore C++23 lambda expressions, where the operator() can omit parentheses when no parameters, even with a capture list, and apply specifiers like mutable, constexpr, const, or eval; see cross-compiler results.
Apply attributes to lambda expressions in C++23 by annotating the overloaded function call operator of the closure, with placement before the parameter list, or before it for template lambdas.
C++23 introduces a static function call operator for stateless function objects, eliminating the this pointer overhead and saving a register.
Apply the static specifier to lambda expressions only when they have no state, avoiding a separate static function and producing a type conversion operator that returns a function pointer address.
Explore the challenge of creating recursive lambdas in c++, showing how std::function and passing self enable recursion, compare with function objects, and note c++23's upcoming simplification.
Explore C++23's deducing this, an explicit object parameter for member functions, enabling self-referential recursive lambdas with auto or template types, and achieving faster performance than stdfunction.
Unlock the full power of callable objects in C++ with this comprehensive journey from traditional C-style callbacks to the very latest C++23 lambda expressions. This course is designed for professional developers who want to move beyond syntax and gain a true, deep understanding of how to write expressive, modern, and highly efficient C++ code.
Start by building a solid foundation with function pointers, exploring the classic C-style approach to callbacks to understand the problems that modern C++ aimed to solve. From there, you will take a deep dive into function objects (functors), learning how to build powerful, stateful operations by creating classes that behave like functions.
Finally, you will progress to lambda expressions. We explore their complete evolution, from the fundamentals in C++11 to the advanced generic and templated features in C++14, C++17, and C++20, all the way to the cutting-edge additions in C++23. By understanding their origins in function pointers and functors, you will see exactly why lambdas are one of the most elegant and powerful features in modern C++.
Whether you're looking to modernize your codebase, master STL algorithms, or simply write cleaner code, this course will give you a complete and confident command of C++'s callable machinery.