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 » Array : swapping element with a pointer
Array : swapping element with a pointer [message #33756] Sat, 10 September 2011 21:30 Go to previous message
mdelfede is currently offline  mdelfede
Messages: 1307
Registered: September 2007
Ultimate Contributor
Hi,

I'd need something like this :

Array[A] array;

A * a = new A;

array.Swap(someIndex, a);



where Array::Swap() should be so :

void Array<A>::Swap(int idx, A*& elem);


This would allow swapping contents of single elements of different arrays without insertion/deletion steps; example :

Array<A> arr1, arr2;

arr1.Add(new A);
arr1.Add(new A);

arr2.Add(new A);
arr2.Add(new A);

A *a = NULL;
arr1.Swap(1, a);
arr2.Swap(1, a);
arr1.Swap(1, a);


That one because I guess removing and then inserting an element in a 10000 elements array just to swap a couple of them would be quite slow....

A more nice way would be some sort of Detach() Set() that don't drop the element but replace it with a dummy (maybe null...) pointer. That would be :

Array<A> arr1, arr2;

arr1.Add(new A);
arr1.Add(new A);

arr2.Add(new A);
arr2.Add(new A);

A *a = arr1.NoDropDetach(1);
A *b = arr2.NoDropDetach(1);
arr1.NoInsertSet(1, b);
arr2.NoInsertSet(1, a);


Max
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Why this one leaks ?
Next Topic: [SOLVED] String.GetCount with umlaut
Goto Forum:
  


Current Time: Sun Jun 02 06:09:37 CEST 2024

Total time taken to generate the page: 0.00652 seconds