x.RC.__postblit () is not callable using argument types () const

Maxim Fomin maxim at maxim-fomin.ru
Tue Feb 5 08:36:15 PST 2013


On Tuesday, 5 February 2013 at 15:49:59 UTC, Dan wrote:
>
> - Wouldn't the scenario be exactly the same without 
> ValuationHistory? That is, if I comment out the member 
> _valuationHistory, the goo member is not changed in structure 
> at all, and yet it compiles just fine.

Scenario is the same if there is struct with postblit and 
const(S) is passed as AA argument. If there is more code 
involved, the situation can be more complicated.

> - Does this mean that "no one" or "very few" developers store 
> structs with postblits as value types in the standard 
> associative array? Maybe I just do things differently than 
> others.

This does not imply such situation, simply there is a problem. 
You can workaround by

struct DAssociativeArray(Key, Value)
{
     struct Slot
     {
         Value value;
     }
}

struct RC {
     int i;
     void postblit() { i = -5; }
     this(this) const
     {
         void delegate() dg = &postblit;
         dg();
     }
}

void main()
{
     RC rc1 = RC(5);
     RC rc2 = rc1;
     assert(rc2.i is -5);
     DAssociativeArray!(int, const(RC)) goo;
}



More information about the Digitalmars-d-learn mailing list