does cast make an lvalue appear to be an rvalue

Dicebot public at dicebot.lv
Wed Oct 16 10:16:37 PDT 2013


On Wednesday, 16 October 2013 at 17:05:25 UTC, Daniel Davidson 
wrote:
> import std.conv;
>
> struct T {
>   int[] i;
>   string[string] ss;
> }
>
> void foo(ref T t) {
> }
>
> void main() {
>   T t1;
>   auto t2 = immutable T();
>   foo(t1);
>   foo(cast()t2);
> }

It works as it should. Make a mutable copy of t2 and pass it. Or 
make foo() accept const. I can't imagine a single legitimate use 
case for destroying type system in a way you want.


More information about the Digitalmars-d-learn mailing list