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++ Library : Other (not classified elsewhere) » Add and AddPick should return reference to added element
Add and AddPick should return reference to added element [message #1674] Mon, 13 March 2006 15:54 Go to next message
hojtsy is currently offline  hojtsy
Messages: 241
Registered: January 2006
Location: Budapest, Hungary
Experienced Member
Vector & Array has these methods:
T&   Add()
void Add(const T& x)
void AddPick(pick_ T& x)
I would like all of these to return reference to added element as in:
T& Add()                 
T& Add(const T& x)
T& AddPick(pick_ T& x)
So that I can write code like array.Add(someThing).ProcessSomething(r);
Re: Add and AddPick should return reference to added element [message #1681 is a reply to message #1674] Mon, 13 March 2006 20:24 Go to previous messageGo to next message
aroman is currently offline  aroman
Messages: 18
Registered: November 2005
Promising Member

Quote:

array.Add(someThing).ProcessSomething(r);


I'm not sure this is a good idea. It gives the impression that ProcessSomething is operating on array rather than someThing.

- Augusto

Re: Add and AddPick should return reference to added element [message #1682 is a reply to message #1681] Mon, 13 March 2006 20:29 Go to previous messageGo to next message
hojtsy is currently offline  hojtsy
Messages: 241
Registered: January 2006
Location: Budapest, Hungary
Experienced Member
You can anyway do array.Add().ProcessSomething(s), so this would just be a harmonization
Re: Add and AddPick should return reference to added element [message #1689 is a reply to message #1681] Mon, 13 March 2006 21:27 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 14105
Registered: November 2005
Ultimate Member
aroman wrote on Mon, 13 March 2006 14:24

Quote:

array.Add(someThing).ProcessSomething(r);


I'm not sure this is a good idea. It gives the impression that ProcessSomething is operating on array rather than someThing.

- Augusto





Actually, I thought that it is not a good idea for exactly the opposite reason - because it operates on the Array, not someThing.

In any case, this different interpretations indicate ambiguous interface.

Mirek
Re: Add and AddPick should return reference to added element [message #1690 is a reply to message #1689] Mon, 13 March 2006 21:47 Go to previous messageGo to next message
hojtsy is currently offline  hojtsy
Messages: 241
Registered: January 2006
Location: Budapest, Hungary
Experienced Member
So what about array.Add().ProcessSomething(s) ? Is that trivial for everyone? The reference is returned for convenience so that client code could operate on the newly inserted element. The same would be needed for the other Add methods.
Re: Add and AddPick should return reference to added element [message #1691 is a reply to message #1690] Mon, 13 March 2006 21:59 Go to previous message
mirek is currently offline  mirek
Messages: 14105
Registered: November 2005
Ultimate Member
hojtsy wrote on Mon, 13 March 2006 15:47

So what about array.Add().ProcessSomething(s) ? Is that trivial for everyone? The reference is returned for convenience so that client code could operate on the newly inserted element. The same would be needed for the other Add methods.


I think there is no ambiguity....

Well, I am not saying that what you propose is a bad idea.... Just during 6 years of current interface I never really felt that this would help.

Maybe it is just that U++ way of coding does not lead to situations where this has any benefit.

Think: you are using Add with parameter variant just for value elements - and you are seldom calling methods for values, much less mutating methods. That is also the source of ambiguity.

Mirek
Previous Topic: Linux SDL [BUG?][WORKAROUND]
Next Topic: subclassing LineEdit is ugly
Goto Forum:
  


Current Time: Fri Nov 01 00:33:16 CET 2024

Total time taken to generate the page: 0.02265 seconds