XML build problems on Windows after latest pull

#21

Hi Jules,

I see you “removed OwnedArray::addIfNotAlreadyThere because it’s ambiguous about whether the object should be deleted if it fails to be added!”

This method still exists for Array… And I can modify my code to deal with the loss of this OwnedArray method… but wouldn’t it have been easier to add a default parameter to deal with the ambiguity rather than just remove the method?

Cheers,

Rail

#22

It’s not a problem in Array because that doesn’t take ownership - it’s only in OwnedArray where it wasn’t clear that if it wasn’t added, the object wouldn’t be deleted, and I bet that it caused a few leaks in people’s code!

I did think about modifying it, but TBH I don’t think the method belongs there at all - I’d rather see code like…

std::unique_ptr<Foo> myFoo = ...

if (! myOwnedArray.contains (myFoo))
    myOwnedArray.add (myFoo.release());

which I think is much better pattern to be following, as the calling code then clearly shows what’s going on in terms of ownership.

2 Likes
#23

OwnedArray::contains is still looking for a raw pointer though…

bool contains (const ObjectClass* objectToLookFor) const noexcept

so…

if (! myOwnedArray.contains (myFoo.get()))
    myOwnedArray.add (myFoo.release());

Rail