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++ TheIDE » U++ TheIDE: Compiling, Linking, Debugging of your packages » Upp::Sort(begin, end, less) does not compile under MSC8 when less is a plain C function
Upp::Sort(begin, end, less) does not compile under MSC8 when less is a plain C function [message #29372] Sat, 16 October 2010 12:35 Go to next message
Didier is currently offline  Didier
Messages: 488
Registered: November 2008
Location: France
Senior Member
Hi all,

I stumbled accross an unexpected compile error that appears only when compiling with MSC8: no problem with GCC.

There is an easy workaround using a functor instead of a plain C compare function.

Is it an MSC8 limitation or a GCC added feature ?!?


Here is a sample code:
#include <Core/Core.h>

using namespace Upp;

typedef Pointf  XY;


bool CompareXY_x(XY a, XY b)
{
	return (a.x < b.x);
}


struct MyLessFunctor {
	bool operator () (const XY& a, const XY& b) const
	{
		return CompareXY_x(a, b);
	}
};

CONSOLE_APP_MAIN
{
	typedef Vector<XY> PointsType;
	
	
	PointsType points;
	
	points << XY(1,2) << XY(2,2) << XY(3,2) << XY(4,2) << XY(6,2);

	Sort(points, CompareXY_x); // Compile on GCC only
	Sort(points, MyLessFunctor() );// compiles on GCC and MSC8
}

[Updated on: Sat, 16 October 2010 12:37]

Report message to a moderator

Re: Upp::Sort(begin, end, less) does not compile under MSC8 when less is a plain C function [message #29376 is a reply to message #29372] Sat, 16 October 2010 13:02 Go to previous messageGo to next message
Didier is currently offline  Didier
Messages: 488
Registered: November 2008
Location: France
Senior Member
Besides this compile issue (which is not really an issue I think).

There is another problem: the sort algorithm is not completely exact:
	while((count = (int)(end - begin)) > __SORT_THRESHOLD) {


The only test that is valid to do on iterators is:
iter1 != iter2 (and of course iter1 == iter2 )

The operation 'end - begin' on iterators is not generic: it may work for the Upp containers, but with others .... ?
Re: Upp::Sort(begin, end, less) does not compile under MSC8 when less is a plain C function [message #29377 is a reply to message #29376] Sat, 16 October 2010 13:12 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 12105
Registered: November 2005
Ultimate Member
Didier wrote on Sat, 16 October 2010 07:02


The only test that is valid to do on iterators is:
iter1 != iter2 (and of course iter1 == iter2 )



Incorrect.

Mirek
Re: Upp::Sort(begin, end, less) does not compile under MSC8 when less is a plain C function [message #29378 is a reply to message #29377] Sat, 16 October 2010 15:13 Go to previous message
Didier is currently offline  Didier
Messages: 488
Registered: November 2008
Location: France
Senior Member
OK

I'm gonna refresh my knowledge
Previous Topic: Exported makefiles don't treat WIN32 flag correctly
Next Topic: Version Tab in .exe properties
Goto Forum:
  


Current Time: Thu Nov 21 06:38:29 CET 2019

Total time taken to generate the page: 0.01213 seconds