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 » FIX FindBest in Algo.h
FIX FindBest in Algo.h [message #43456] Wed, 06 August 2014 16:56 Go to next message
masu is currently offline  masu
Messages: 378
Registered: February 2006
Senior Member
Hi,

I took a look into Algo.h especially the Min and Max functions.
Both functions call FindBest (starting at line 64) which I think should be fixed, because it does not respect its pos and count parameters appropriately.

Here is the fix:

template <class C, class Pred>
int FindBest(const C& c, int pos, int count, const Pred& pred)
{
===>	if(c.GetCount() == 0)
		return -1;
	typename C::ValueType m = c[pos];
	int mi = pos;
===>	for(int i = pos+1; i < count; i++)
		if(pred(c[i], m)) {
			m = c[i];
			mi = i;
		}
	return mi;
}


Regards
Matthias


931b81e7ea53320dccc37375b34b38c3
Re: FIX FindBest in Algo.h [message #43457 is a reply to message #43456] Wed, 06 August 2014 17:51 Go to previous message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Thanks you are right. In the process I have also removed requirement of deep copy.
Previous Topic: Is XML compression possible by U++ library call?
Next Topic: HttpRequest : problem with multiple redirections ?
Goto Forum:
  


Current Time: Fri Apr 19 00:16:31 CEST 2024

Total time taken to generate the page: 0.06455 seconds