On Sunday, 4 November 2012 at 21:44:15 UTC, Tobias Pankrath wrote:
I don't think that currently qualifiers work with the postblit
constructor. See here for a related discussion.
http://forum.dlang.org/thread/CAFDvkcvvL8GxHQB=Rw9pTm-uxOKzNGVQNDv9w5Os3SkQCc=d...@mail.gmail.com
Thanks. The reason I'm down this path is something like below. I
really want to keep const ref for parms on a method (e.g. foo
below). It turns out the type is a assoc array and length and
keys are both giving me a headache. Without the cast I get a
message like:
Error: function acct.Account.__postblit () is not callable using
argument types () const
Below I cast away const (Dohh!). Is it safe in this case?
If not is there another way?
Thanks,
Dan
import std.stdio;
import std.traits;
alias Account[string] Map;
struct Account {
this(this){ writeln("acct copied"); }
}
void foo(const ref Map m) {
pragma(msg, "Map is ", typeof(m));
pragma(msg, "Map is ", typeof(cast()m));
writeln("Map has ", (cast(Map)m).length);
writeln("Map has ", (cast(Map)m).keys);
}
void main() {
Map map;
Account acct;
foo(map);
}