|
|
Home » U++ Library support » U++ Core » why not "T & Add(const T & x)" in all containers
Re: why not "T & Add(const T & x)" in all containers [message #28605 is a reply to message #28588] |
Wed, 08 September 2010 10:24   |
rylek
Messages: 79 Registered: November 2005
|
Member |
|
|
Hi there!
It is a pleasure to play the third party, though the semantics of the term are highly disputable here. I think it's possible Mirek originally didn't include the return reference in Vector::Add to emphasize the fact that such references into Vectors are volatile in principle (specifically they are periodically invalidated by the Add function itself while reallocating the physical Vector data). But, of course, the same argument holds for Add() which does return the reference. Moreover, Array::Add(T *newobj) also returns the reference, albeit for different reasons.
U++ also decidedly avoids returning references in pick assignment operators, which is natural because a "chain" assignment (a = b = c) in such cases exhibits undesirable behaviour (by destroying b). But Vector::Add(const T&) doesn't have this problem; the only thing that has to be avoided is rather artificial constructs of the form
vector.Add(vector.Add(obj))
exactly because of the periodical Vector reference invalidation. But then again you can run into exactly the same problems by writing, e.g.
so that this is no specific of Vector::Add(const T&) either. To sum it all up, I currently see no practical reasons against modifying Vector::Add to include the return reference. I would rather say that it's like updating old code to match interface standards adopted / developed later on, in fact I believe Vector is one of the very oldest things in U++ (although it's been rewritten quite a few times since its inception).
Regards
Tomas
|
|
|
 |
|
why not "T & Add(const T & x)" in all containers
|
 |
|
Re: why not "T & Add(const T & x)" in all containers
By: kohait00 on Tue, 03 August 2010 11:15
|
 |
|
Re: why not "T & Add(const T & x)" in all containers
|
 |
|
Re: why not "T & Add(const T & x)" in all containers
By: kohait00 on Tue, 03 August 2010 16:06
|
 |
|
Re: why not "T & Add(const T & x)" in all containers
|
 |
|
Re: why not "T & Add(const T & x)" in all containers
By: kohait00 on Wed, 04 August 2010 09:57
|
 |
|
Re: why not "T & Add(const T & x)" in all containers
By: kohait00 on Thu, 05 August 2010 08:35
|
 |
|
Re: why not "T & Add(const T & x)" in all containers
By: mrjt on Thu, 05 August 2010 09:55
|
 |
|
Re: why not "T & Add(const T & x)" in all containers
By: kohait00 on Thu, 05 August 2010 10:10
|
 |
|
Re: why not "T & Add(const T & x)" in all containers
By: mirek on Fri, 06 August 2010 11:27
|
 |
|
Re: why not "T & Add(const T & x)" in all containers
By: kohait00 on Fri, 06 August 2010 11:48
|
 |
|
Re: why not "T & Add(const T & x)" in all containers
By: kohait00 on Mon, 09 August 2010 08:50
|
 |
|
Re: why not "T & Add(const T & x)" in all containers
By: mirek on Fri, 13 August 2010 09:38
|
 |
|
Re: why not "T & Add(const T & x)" in all containers
By: kohait00 on Mon, 16 August 2010 09:06
|
 |
|
Re: why not "T & Add(const T & x)" in all containers
By: kohait00 on Mon, 30 August 2010 10:46
|
 |
|
Re: why not "T & Add(const T & x)" in all containers
By: mirek on Mon, 06 September 2010 10:53
|
 |
|
Re: why not "T & Add(const T & x)" in all containers
By: kohait00 on Mon, 06 September 2010 11:52
|
 |
|
Re: why not "T & Add(const T & x)" in all containers
By: mirek on Wed, 08 September 2010 09:00
|
 |
|
Re: why not "T & Add(const T & x)" in all containers
By: rylek on Wed, 08 September 2010 10:24
|
 |
|
Re: why not "T & Add(const T & x)" in all containers
By: kohait00 on Wed, 08 September 2010 10:54
|
 |
|
Re: why not "T & Add(const T & x)" in all containers
By: mirek on Wed, 08 September 2010 11:30
|
 |
|
Re: why not "T & Add(const T & x)" in all containers
By: mirek on Fri, 17 September 2010 08:11
|
 |
|
Re: why not "T & Add(const T & x)" in all containers
By: kohait00 on Fri, 17 September 2010 09:15
|
 |
|
Re: why not "T & Add(const T & x)" in all containers
By: kohait00 on Thu, 21 October 2010 09:02
|
 |
|
Re: why not "T & Add(const T & x)" in all containers
By: mirek on Thu, 21 October 2010 11:10
|
 |
|
Re: why not "T & Add(const T & x)" in all containers
By: kohait00 on Thu, 21 October 2010 11:54
|
 |
|
Re: why not "T & Add(const T & x)" in all containers
By: kohait00 on Wed, 30 March 2011 10:54
|
 |
|
Re: why not "T & Add(const T & x)" in all containers
By: mirek on Sat, 16 April 2011 20:31
|
 |
|
Re: why not "T & Add(const T & x)" in all containers
By: kohait00 on Sun, 17 April 2011 14:46
|
 |
|
Re: why not "T & Add(const T & x)" in all containers
By: mirek on Sun, 17 April 2011 21:43
|
 |
|
Re: why not "T & Add(const T & x)" in all containers
By: kohait00 on Mon, 18 April 2011 09:00
|
Goto Forum:
Current Time: Mon Aug 25 11:00:31 CEST 2025
Total time taken to generate the page: 0.04685 seconds
|
|
|