Expression Templates
Explore expression templates and their role in C++ lazy evaluation. Learn how they eliminate unnecessary temporary objects in arithmetic expressions, improving runtime efficiency and memory usage by delaying computation until needed. Understand this advanced technique that supports creating domain-specific languages and reducing overhead in complex computations.
We'll cover the following...
Expression Templates
Expression templates are “structures representing a computation at compile-time, which are evaluated only as needed to produce efficient code for the entire computation.”
Now we are at the center of lazy evaluation.
Lazy Evaluation
The story about lazy evaluation in C++ is quite short. That will change in C++20, with the ranges library from Eric Niebler. Lazy evaluation is the default in Haskell. Lazy evaluation means that an expression is only evaluated when needed.
This strategy has two benefits.
- Lazy evaluation helps you to