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 » why not "T & Add(const T & x)" in all containers
Re: why not "T & Add(const T & x)" in all containers [message #28619 is a reply to message #28605] Wed, 08 September 2010 11:30 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
rylek wrote on Wed, 08 September 2010 04:24


exactly because of the periodical Vector reference invalidation. But then again you can run into exactly the same problems by writing, e.g.

vector.Add(vector[5]);





Actually, above code is OK, this was already improved (because improvement is possible by changing the order of operations in implementation).

The only last one in this zone is Insert... (which right now ASSERTs, but I guess it should be fixed too).

Mirek
Re: why not "T & Add(const T & x)" in all containers [message #28792 is a reply to message #28619] Fri, 17 September 2010 08:11 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
OK, it now returns T&...
Re: why not "T & Add(const T & x)" in all containers [message #28794 is a reply to message #28792] Fri, 17 September 2010 09:15 Go to previous messageGo to next message
kohait00 is currently offline  kohait00
Messages: 939
Registered: July 2009
Location: Germany
Experienced Contributor
hi mirek, thanks.
just a question aside: why does DeepCopyConstryct return T& instead of T*? it kinda differs from the other 'patterns' DeepCopyNew, ::new(p) T() etc..which all return T* at that level.

EDIT: i think i understand why..there occure strange compile errors for ArrayCtrl Vector< Vector< Value > > things. and i kind of cant figure out why and how to potentially fix it.

nonetheless, Add is done, what about Insert and Set behaviour? should do the same..

i've added the current proposal, based on your changes.
  • Attachment: Core.rar
    (Size: 310.15KB, Downloaded 169 times)

[Updated on: Fri, 17 September 2010 10:33]

Report message to a moderator

Re: why not "T & Add(const T & x)" in all containers [message #29447 is a reply to message #28794] Thu, 21 October 2010 09:02 Go to previous messageGo to next message
kohait00 is currently offline  kohait00
Messages: 939
Registered: July 2009
Location: Germany
Experienced Contributor
kohait00 wrote on Fri, 17 September 2010 09:15

hi what about Insert and Set behaviour? should do the same..


just a reminder, since i've still got the changes around in my code, just to know if they once might become upstream. or what your position is..
Re: why not "T & Add(const T & x)" in all containers [message #29449 is a reply to message #29447] Thu, 21 October 2010 11:10 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
kohait00 wrote on Thu, 21 October 2010 03:02

kohait00 wrote on Fri, 17 September 2010 09:15

hi what about Insert and Set behaviour? should do the same..


just a reminder, since i've still got the changes around in my code, just to know if they once might become upstream. or what your position is..


Insert/Set has sort of problem as it can insert more than single element, and even worse, it can insert ZERO elements. (Note that for single element it already returns T&).
Re: why not "T & Add(const T & x)" in all containers [message #29450 is a reply to message #29449] Thu, 21 October 2010 11:54 Go to previous messageGo to next message
kohait00 is currently offline  kohait00
Messages: 939
Registered: July 2009
Location: Germany
Experienced Contributor
i thought of it. and there is a solution in the code.
i just split the function, i.e. Set:

original:
	void     Set(int i, const T& x, int count = 1);


split:
	T&       Set(int i, const T& x);
	void     Set(int i, const T& x, int count);

which is syntactically the same, the omited count defaults to setting only one element and returns the ref..no changes in user code. when using count, the other function evaluates.

insert is same:
	void     Insert(int i, const T& x, int count = 1);


split:
	T&       Insert(int i, const T& x);
	void     Insert(int i, const T& x, int count);


i'm actually working with the code for some while now, and haven't noticed any misbehavior, so the sub layers of upp deal well with it. consider it again. i think it can contribute to the comfort using upp containers, and of corse again a little bit of speed optimization at user level..and shorten the code a bit.

attached the current source based snapshot..
Re: why not "T & Add(const T & x)" in all containers [message #31830 is a reply to message #29450] Wed, 30 March 2011 10:54 Go to previous messageGo to next message
kohait00 is currently offline  kohait00
Messages: 939
Registered: July 2009
Location: Germany
Experienced Contributor
just wanted to poke gently w.r.t that issue..
i've got some fixes in my local tree and am cleaning up Smile

is there interest/chance for this to be upstream sometime or should i consider it lost? (future coding needs to take account of it)
Re: why not "T & Add(const T & x)" in all containers [message #32000 is a reply to message #31830] Sat, 16 April 2011 20:31 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
OK. I really dislike this change, but I cannot bring any rational argument against it.

So it is now in Core Smile
Re: why not "T & Add(const T & x)" in all containers [message #32018 is a reply to message #32000] Sun, 17 April 2011 14:46 Go to previous messageGo to next message
kohait00 is currently offline  kohait00
Messages: 939
Registered: July 2009
Location: Germany
Experienced Contributor
cool..

just for completion sake..there are those changes for Map and Index, that can expose their elements now as well, just by using the api..was it your intention?

for easy handling, i just packed them, so you can replace them for svn review. to current revision 3346

there is also the Insert(int i, T* newt) that seems to be overseen.
thats why Vcont.h and .hpp are in the rar as well.

it'd be nice to have all together

thanks for your time Smile
  • Attachment: Core.rar
    (Size: 12.53KB, Downloaded 177 times)
Re: why not "T & Add(const T & x)" in all containers [message #32022 is a reply to message #32018] Sun, 17 April 2011 21:43 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Sight... great, another change I really hate.

OK, it is there. I have even "fixed" some inserts you forgot... Smile
Re: why not "T & Add(const T & x)" in all containers [message #32029 is a reply to message #32022] Mon, 18 April 2011 09:00 Go to previous message
kohait00 is currently offline  kohait00
Messages: 939
Registered: July 2009
Location: Germany
Experienced Contributor
thats definitely cool, thanks a bunch..
Previous Topic: InitCaps() proposal
Next Topic: Incorrect implementation of INITBLOCK (and similar macros) in case when flagBLITZ is not defined.
Goto Forum:
  


Current Time: Fri May 03 21:24:59 CEST 2024

Total time taken to generate the page: 0.01918 seconds