Evaluation Order in C++17
Explore the changes in evaluation order introduced in C++17 that ensure inner expressions and operator overloads are executed from left to right. Understand how this impacts function chaining and operator overloading behavior, improving code clarity and predictability.
We'll cover the following...
We'll cover the following...
The example case
You probably expect that using C++14 computeInt() happens after addFloat. Unfortunately, that
might not be the case. For instance here’s an output from GCC 4.7.3:
computing int...
computing float...
addFloat: 10.1
addInt: 8
The chaining of functions is already specified to work from left to right (thus addInt() happens after addFloat()), but the order of evaluation of the inner expressions can differ. To be precise:
The expressions are indeterminately sequenced with respect to each other.
With C++17, ...