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
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
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
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
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 ?
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
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);