returning 'ref inout(T)' - not an lvalue?

Adam D. Ruppe via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Jan 25 13:04:50 PST 2017


On Wednesday, 25 January 2017 at 20:42:52 UTC, bitwise wrote:
> Is it not possible to return a ref from an inout function?

It isn't the inout that's getting you, it is the const object in 
main().

     const(List!int) c;

Make that mutable and it works. Why? Cuz the `C list` in the 
iterator keeps that const with it.... I'm not sure why that kills 
it though, the error tells me it is an internal cast that is 
breaking things but I don't see why that logically would.

This might arguably be a bug, but you could work around it by 
checking for that const This and offering a different method that 
just returns const instead of ref.

>     T[] data = new T[1];

BTW what do you think this line does? I ask because most people 
who use it don't get what they expect out of it....


More information about the Digitalmars-d-learn mailing list