On Saturday, 9 December 2017 at 06:46:27 UTC, Arun Chandrasekaran
wrote:
Thanks. Just curious why reference can't be obtained here.
Saves nasty null checks in most places.
D simply doesn't have a (C++-style) concept of references as part
of the type. Arguments can be passed by reference - hence the
`ref` keyword -, but "free" references don't exist in the
language.
The ref in foreach loop variables can be conceptually thought of
as a parameter to the loop body as well. (For opApply-based
iteration, the loop body indeed gets turned into a function; for
"plain" iteration the compiler AST internally has special ref
variables, but they are not visible to the language.)
-David