Collections question

Steven Schveighoffer via Digitalmars-d digitalmars-d at puremagic.com
Mon Nov 30 08:28:11 PST 2015


On 11/30/15 11:21 AM, Tobias Pankrath wrote:
> On Monday, 30 November 2015 at 16:06:43 UTC, Steven Schveighoffer wrote:
>> MyCollection!(int) c1;
>> auto c2 = c1;
>> c1 ~= 1;
>>
>> assert(c2.contains(1)); // pass? fail?
>>
>> BTW, I third Jonathan's and Timon's suggestion -- go with an external
>> factory function. Use IFTI to its fullest!
>
> That should throw, because you're using an uninitialised reference (c1).
> It's the equivalent to:
>
> Class C { .. }
>
> C c1;
> C c2 = c1;
> c1.foo(); // call via nullptr
>
> Or it needs to pass, but that's probably not worth it.

It means such a collection won't operate in the same way that 
associative arrays do.

If that's the case, I'm OK with that.

Technically, a wrapper could be constructed that performed the "lazy 
creation".

But my point to Andrei was that the functions he suggests don't actually 
address the "oddity" of copying AAs. Addressing it, if it's done in the 
way you say, is as simple as not worrying about null pointers.

-Steve


More information about the Digitalmars-d mailing list