Serious problem with opCmp

Bill Baxter dnewsgroup at billbaxter.com
Sun Mar 2 14:06:00 PST 2008


kov_serg wrote:
> Bill Baxter Wrote:
> 
> In C++ code solution may looks like:
> 
> template<class T>int compare(const T& lv,const T& rv) {
> 	return lv<rv?-1: rv<lv?+1: 0;
> }
> 
> and using it like this
> struct S {
> 	int a,b;
> 	static int cmp(const S& lv,const S& rv) {
> 		int t=compare(lv.a,rv.a); if (t) return t;
> 		return compare(lv.b,rv.b);
> 	}
> };
> any case it will requires from me only operator<

I'm not sure what point you're trying to make now?
Are you saying D should be like C++ and require only opLess?
I don't think that's going to happen.

But I do think the examples of using opCmp should be changed to be more 
like "return lv<rv?-1: rv<lv?+1: 0;" as you said (where lv is member of 
'this' in the D version).

--bb



More information about the Digitalmars-d mailing list