initializing const maps with value types having aliasing
Dan
dbdavidson at yahoo.com
Wed Mar 20 11:41:00 PDT 2013
The following works and is the only way I have found to
initialize m.
Unfortunately it requires the cast.
Is this safe to do?
Is there a better way?
Is this a bug or are future features coming to clean it up?
Thanks
Dan
----------------------------------
import std.stdio;
struct S {
this(this) { x = x.dup; }
char[] x;
}
const(S[string]) m;
static this() {
// Is there a cleaner way?
cast(S[string])m = [ "foo" : S(['a']) ];
}
void main() {
writeln(m["foo"]);
}
More information about the Digitalmars-d-learn
mailing list