On Wednesday, 16 October 2013 at 18:09:55 UTC, Maxim Fomin wrote:
On Wednesday, 16 October 2013 at 17:05:25 UTC, Daniel Davidson wrote:
The code below fails to compile due to the last line. I was hoping casting away immutable would allow the call to foo. I think it is not accepted because of the rval to ref issue. If that is the case, how can foo be called by casting?

I'm not a fan of casting but I'm finding cases where it is the only recourse to create immutable data using impure functions that should be pure.

Thanks
Dan

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);
}

foo([cast()t2][0]);

(It would be good to have compound literals like in C)

Haaah - brilliant. Scary, but brilliant.

Reply via email to