Postponing sqrt Computations
Explore how to optimize vector length comparisons in C++ by using proxy objects to defer costly sqrt operations. This lesson helps you understand lazy evaluation to improve performance without sacrificing code readability.
We'll cover the following...
We'll cover the following...
This section will show you how to use a proxy object to postpone, or even avoid, using the computationally heavy std::sqrt() function when comparing the length of two-dimensional vectors.
A simple two-dimensional vector class
Let’s start with a simple two-dimensional vector class. It has and ...