question on [Issue 7853]

Dan dbdavidson at yahoo.com
Sun Nov 4 17:24:18 PST 2012


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=DLQ@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);
}


More information about the Digitalmars-d-learn mailing list