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 » Vector<T>::Set(int i, T&& x) proposal
Re: Vector<T>::Set(int i, T&& x) proposal [message #49366 is a reply to message #49345] Wed, 31 January 2018 19:34 Go to previous messageGo to previous message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Novo wrote on Tue, 30 January 2018 03:30
mirek wrote on Sun, 28 January 2018 16:47
I am considering this, but single element Set was always just v.At(i) = pick(src);

Well, yes. This will work as well. But this is significantly less intuitive. Your way of solving this problem definitely didn't come to my mind when I was looking for a solution. Adding of an rvalue-based version of Set definitely won't break API because you already have a reference-based version. This is just another performance optimization.

My solution is based on move-constructor and yours is based on move-operator.


OK. After further thinking, for some time now I think it is worthwhile to add

const T& Vector::Get(int i, const T& default) { return i >= 0 && i < GetCount() ? Get(i) : default; }


Set makes a nice complement to this, so it makes sense to add Set(int, T&&) too.

Do you see any problem with trivial implementation

void Vector::Set(int i, T&& x) { At(i) = pick(x); }


?

BTW, this is simple. But if I am about to add it here, I have to do that for every container where it makes sense and fill documentation too, add autotests. Thats just to explain my hesitation...
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Function.h: "expression cannot be used as a function"
Next Topic: Core/SSL crashes at exit on Linux.
Goto Forum:
  


Current Time: Sat May 04 00:27:36 CEST 2024

Total time taken to generate the page: 0.03292 seconds