Lvalues and Rvalues
Explore the concepts of lvalues and rvalues in D programming to understand how expressions are classified, their limitations, and their impact on function parameters. This lesson explains the difference between values with memory addresses and temporary results, and introduces how auto ref parameters handle them in function templates.
We'll cover the following...
The difference between lvalues and rvalues
The value of every expression is classified as either an lvalue or an rvalue. A simple way of differentiating the two is thinking of lvalues as actual variables (including elements of arrays and associative arrays) and rvalues as temporary results of expressions (including literals).
As a demonstration, the first writeln() expression below uses only values, and the other one uses only rvalues:
Limitations of rvalues
Compared to lvalues, rvalues have the following three ...