Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Core » Inconsistency between Vector and Index
Inconsistency between Vector and Index [message #52130] Tue, 23 July 2019 03:34 Go to next message
Novo is currently offline  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 #52131 is a reply to message #52130] Tue, 23 July 2019 09:21 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
You are right, fixed.
Re: Inconsistency between Vector and Index [message #52136 is a reply to message #52131] Wed, 24 July 2019 05:20 Go to previous message
Novo is currently offline  Novo
Messages: 1358
Registered: December 2006
Ultimate Contributor
mirek wrote on Tue, 23 July 2019 03:21
You 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
Previous Topic: MemorySanitizer: use-of-uninitialized-value in CoWork
Next Topic: Problem with LanguageInfo
Goto Forum:
  


Current Time: Fri Mar 29 02:53:54 CET 2024

Total time taken to generate the page: 0.01173 seconds