This video, the first part of a series, introduces expression templates in C++. Joel Falcou explains the fundamental concepts, motivations, and the historical context of expression templates, aiming to demystify this complex technique. He covers how they work by representing expressions as trees and how this representation can be leveraged for optimization, particularly to avoid temporary object creation in complex algebraic expressions. The talk also touches upon the challenges and evolution of expression templates in C++.
CRTP is used to simulate runtime polymorphism at compile time. This allows different expression types (like unary, binary, and terminals) to share a common interface within the expression template system. Each derived expression class inherits from a base class, passing its own type as a template parameter to the base. This enables functions in the base class to statically cast this to the derived type and call derived-specific methods, effectively dispatching operations at compile time without the overhead of virtual function calls.