x.RC.__postblit () is not callable using argument types () const
Dan
dbdavidson at yahoo.com
Tue Feb 5 07:49:58 PST 2013
On Tuesday, 5 February 2013 at 15:06:47 UTC, Maxim Fomin wrote:
> The root of the problem is in:
>
> struct DAssociativeArray(Key, Value)
> {
> struct Slot
> {
> Value value;
> }
> }
>
> struct RC {
> this(this) { }
> }
>
> void main()
> {
> DAssociativeArray!(int, const(RC)) goo;
> }
>
> which doesn't compile (this is how Value[Key] is rewritten).
>
I see - thanks. I assume it should compile and without the
postblit it does. So - the original code is fine and there is a D
problem with associative arrays.
- 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.
- 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.
The way I see it you have to choose how you want to develop your
structs/classes. I have chosen to use structs and templates and
avoid classes, thinking this would greatly simplify things. Any
struct needs to establish up front whether it will have value
semantics or reference semantics. So far, I have preferred value
semantics as data sharing leads to confusion. So if I have arrays
in a struct I include postblits to provide value semantics. In
another thread Walter made clear his distaste for postblits and
preference for reference semantics coupled with copy on write
semantics where needed. That approach, just does not seem worth
it without more systematic support for COW. Assuming postblits
are the issue, I don't understand why they are so hard to get
right.
Thanks
Dan
More information about the Digitalmars-d-learn
mailing list