dlang.org
dlang.org copied to clipboard
Allow `ref` and `auto ref` in `IfCondition` declarations
As DIP 1046 (ref
For Variable Declarations) has been accepted, probably, ref
(and auto ref
) should be allowed for the condition in if
, while
, and switch
statements:
int** pptr = …;
if (ref int* ptr = *pptr) …;
Of course, the condition tests whether the variable (ptr
in the example) is true
-like, not whether the reference is a non-null reference. In the example, it tests ptr !is null
, and not &ptr !is null
(or, equivalently, pptr !is null
).
if (auto ref x = mystery()) …;
Especially in template contexts, auto ref
could be used to make x
be a ref
if mystery()
returns by reference, but a value otherwise.