On Monday, December 24, 2012 20:03:24 monarch_dodra wrote: > Hum... Indeed, it takes by ref *and* returns by ref. Passing in > to out a const ref is *the* smoking gun. Working with D has > gotten me used to functions that take by value and return by > value... > > Snap. You got me.
It wouldn't matter if the function accepted its argument by value. You'd still be returning a reference to a variable that doesn't exist anymore. If anything, it would be _worse_ if it took it by value, since the variable definitely doesn't exist anymore once the function returns in that case, whereas with a reference, it will continue to exist for the duration of the statement that the call was made in (and beyond that, if the argument was actually an lvalue - in fact with an lvalue, the code would work as unsafe is it may be). So, it's the returning by reference that's the problem, not passing by reference. - Jonathan M Davis
