does cast make an lvalue appear to be an rvalue

Dicebot public at dicebot.lv
Wed Oct 16 11:55:50 PDT 2013


On Wednesday, 16 October 2013 at 18:14:22 UTC, Daniel Davidson 
wrote:
> I agree with the sentiment. But as it stands I think a copy 
> should not be necessary. I could make a local mutable R, pass 
> it to createRFromT to get it initialized and then copy it back 
> somehow to the member variable r. That to me is silly. The copy 
> should not be required.

Then don't use immutable. Root of all problems with immutable 
comes from trying to use it for something it should never be. 
`immutable` means "never ever can be accessed with a mutable" 
with any compiler optimization that may come from that. Any cast 
is undefined behavior in a form of time bomb. Basically, only 
thing immutable is good at is to create some potentially shared 
data and slicing / reading it when needed. If you need the same 
data but for passing as mutable function argument, you MUST make 
a copy, there is no safe way around it.


More information about the Digitalmars-d-learn mailing list