Kinds of containers
Andrei Alexandrescu via Digitalmars-d
digitalmars-d at puremagic.com
Wed Oct 21 07:36:43 PDT 2015
On 10/21/2015 10:21 AM, Timon Gehr wrote:
>>
>
> I still think those should be mutable by default in order to have
> painless interchangeability with other value type containers. Why should
> corresponding ephemeral and persistent containers have different
> interfaces?
>
> I assume you envision code using those to look as follows?
>
> FunSet!int a;
> a=a.with_(1);
> auto b=a;
> a=a.with_(2);
> a=a.with_(3);
> // b = {1}, a={1,2,3};
>
> I think this should be allowed too:
>
> FunSet!int a;
> a.insert(1);
> auto b=a;
> a.insert(2);
> a.insert(3);
> // b = {1}, a={1,2,3};
>
> One of the two versions should be automatically implemented via UFCS.
I recall you and I discussed this briefly in the past, but forgot the
conclusion.
So are you saying that a.insert(1) is really rebinding a to be its
former value plus a new slot? I.e a.insert(1) is the same as a =
a.with_(1)? That would work, but only if former reads of a refer to the
old data. E.g.:
FunSet!int a;
auto b = a;
assert(a.empty && b.empty);
a.insert(1);
assert(!a.empty && b.empty);
Right?
Andrei
More information about the Digitalmars-d
mailing list