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 » Proposal: BinFindIndex should return 0 for empty container
Proposal: BinFindIndex should return 0 for empty container [message #5061] Fri, 01 September 2006 19:41 Go to next message
hans is currently offline  hans
Messages: 44
Registered: March 2006
Location: Germany
Member
Currently BinFindIndex returns -1 if container is empty.

As the returned value is the slot where the element could be inserted with correct sorting, it would be possible to return 0
for empty container.
The returned value can always be out of valid range index, so I see no point for special case for empty container.

This would avoid some test code in client:

 Vector<String> v;
 v.Add(L"alf");
 v.Add(L"berta");
 v.Add(L"caesar");

 ..
 // some func getting v (possibly empty)
 String s= L"x";
 int n= BinFindIndex(v, s); // returns 3. 
 if (n<0) n= 0; // currently client must cope with empty container case
 v.Insert(n, s);

Re: Proposal: BinFindIndex should return 0 for empty container [message #5065 is a reply to message #5061] Sat, 02 September 2006 00:15 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
hans wrote on Fri, 01 September 2006 13:41

Currently BinFindIndex returns -1 if container is empty.



I am not sure. I see if(begin==end) return 0; in my version...

Mirek


Re: Proposal: BinFindIndex should return 0 for empty container [message #5078 is a reply to message #5065] Sat, 02 September 2006 12:36 Go to previous message
hans is currently offline  hans
Messages: 44
Registered: March 2006
Location: Germany
Member
You are right, I compared to an old upp version.
Sorry for the confusion Sad
Previous Topic: bug: AtomicXAdd for non win32, non-posix returns wrong value
Next Topic: what technique does U++ use to reduce code bloat from too many template instantiations?
Goto Forum:
  


Current Time: Sat Apr 27 11:19:36 CEST 2024

Total time taken to generate the page: 0.04977 seconds