Home » U++ Library support » U++ Core » Inconsistency between Vector and Index
Inconsistency between Vector and Index [message #52130] |
Tue, 23 July 2019 03:34 |
Novo
Messages: 1358 Registered: December 2006
|
Ultimate Contributor |
|
|
Vector<int> vi = {1, 2, 3};
Vector<Vector<int>> vvi;
Index<Vector<int>> ivi;
vvi.Add(vi); // clones vi.
ivi.Add(vi); // fails to compile
Vector::Add implicitly clones its argument. This is what Index::Add used to do in the past.
New Index will now ask you what exactly you want to do with the argument (pick or clone).
IMHO, this is inconsistent.
IMHO, nothing is supposed to be "secretly" cloned behind the scene.
I would say that current behavior of Vector::Add is incorrect.
Just my two cents.
Regards,
Novo
|
|
|
|
Re: Inconsistency between Vector and Index [message #52136 is a reply to message #52131] |
Wed, 24 July 2019 05:20 |
Novo
Messages: 1358 Registered: December 2006
|
Ultimate Contributor |
|
|
mirek wrote on Tue, 23 July 2019 03:21You are right, fixed.
Thanks!
It looks like the issue is still not fixed completely because GrowAdd(const T& x) still calls clone(x).
Also, Array::Add(const T& x) still makes a clone.
Vector::Insert(int i, const T& x) also makes a clone.
IMHO, this issue with clone is a fundamental change of a design. It is, probably, easier to change Index to make clone instead.
Changing semantics of XXX(const T& x) calls will break a lot of code.
It is up to you to decide how it will work in the future.
Regards,
Novo
|
|
|
Goto Forum:
Current Time: Sun Apr 28 04:37:25 CEST 2024
Total time taken to generate the page: 0.06678 seconds
|