Re: Template function : use the array's one !

2009-02-18 Thread TSalm
TSalm Wrote: int compare(T:T[])(T[] o1,T[] o2) Change this line to: int compare(T:T[])(T o1, T o2) You are right. But despite this function, at compile time, an error is return : .\src\tsalm\tools\Generic.d(20): Error: cannot implicitly convert expression (o2 - o1) of type int[3u] t

Re: Template function : use the array's one !

2009-02-18 Thread John C
TSalm Wrote: > Hello, > > I'm searching to have a generic comparator function. > > I done this : > > /* CODE */ > import tango.io.Stdout; > > /*** > * Not for arrays > ***/ > int compare(T)(T o1,T o2) > { >static if ( is( T bar == class ) || is( T

Re: Template function : use the array's one !

2009-02-17 Thread TSalm
Le Tue, 17 Feb 2009 23:03:04 +0100, BCS a écrit: Hello TSalm, take a look at static if and is http://www.digitalmars.com/d/1.0/version.html#staticif http://www.digitalmars.com/d/1.0/expression.html#IsExpression Thanks for this links. But I don't see anything about how to test if it's an ar

Re: Template function : use the array's one !

2009-02-17 Thread BCS
Hello TSalm, take a look at static if and is http://www.digitalmars.com/d/1.0/version.html#staticif http://www.digitalmars.com/d/1.0/expression.html#IsExpression Thanks for this links. But I don't see anything about how to test if it's an array or not... Is it not possible ? look at point 5

Re: Template function : use the array's one !

2009-02-17 Thread TSalm
take a look at static if and is http://www.digitalmars.com/d/1.0/version.html#staticif http://www.digitalmars.com/d/1.0/expression.html#IsExpression Thanks for this links. But I don't see anything about how to test if it's an array or not... Is it not possible ?

Re: Template function : use the array's one !

2009-02-17 Thread BCS
Reply to TSalm, Hello, I'm searching to have a generic comparator function. I done this : [...] How can I declare this compare function to use specific code to compare arrays ? Thanks in advance, TSalm take a look at static if and is http://www.digitalmars.com/d/1.0/version.html#static

Template function : use the array's one !

2009-02-17 Thread TSalm
Hello, I'm searching to have a generic comparator function. I done this : /* CODE */ import tango.io.Stdout; /*** * Not for arrays ***/ int compare(T)(T o1,T o2) { static if ( is( T bar == class ) || is( T bar == struct ) ) return o1.opCmp(o2);