On 19.04.2011 16:57, Sequ wrote:
Like the topic says, is it possible to set a custom compare function, for when
you are using the 'sort' property of an integer array? I want the integers to
be sorted by a different criteria than their natural order. From the
documentation
On 19.04.2011 16:56, Dmitry Olshansky wrote:
If you are talking use std.algorithm sort
Should be: If your are talking about D2, then use std.algorithm sort
, ouch :)
--
Dmitry Olshansky
If your are talking about D2, then use std.algorithm sort
Like taken from docs below:
bool myComp(int x,int y) {return x y; }
sort!(myComp)(array);
See also:
http://www.digitalmars.com/d/2.0/phobos/std_algorithm.html#sort
--
Dmitry Olshansky
Ah, yes, thanks; that looks like it
Andrej Mitrovic Wrote:
int foo(ref int y)
{
y = 5;
return y;
}
void main()
{
int x = 1;
int y = 2;
switch (x = foo(y))
{
case y:
writeln(x == y);
default:
}
assert(x == 5);
assert(y == 5);
}
Yes bug.
On 4/19/11, Jesse Phillips jessekphillip...@gmail.com wrote:
Yes bug. Not this part though
switch (x = foo(y))
Yeah that I know.
Do you happen to know if this bug is already filed or should I file it?
*I've searched bugzilla and couldn't find an entry for this particular case.
Andrej Mitrovic Wrote:
On 4/19/11, Jesse Phillips jessekphillip...@gmail.com wrote:
Yes bug. Not this part though
switch (x = foo(y))
Yeah that I know.
Do you happen to know if this bug is already filed or should I file it?
I would not know. As long as you do a best guess
Got it. Bug is reported.
Btw, is there a specific reason why non-const values are not allowed?
I mean, doesn't a switch statement like this:
switch(value)
{
case 1:
foo(); break;
case 2:
bar(); break;
default:
doo();
}
expand to:
if (value == 1)
foo();
Andrej Mitrovic Wrote:
Got it. Bug is reported.
Btw, is there a specific reason why non-const values are not allowed?
I mean, doesn't a switch statement like this:
switch(value)
{
case 1:
foo(); break;
case 2:
bar(); break;
default:
doo();
}
Andrej Mitrovic:
Got it. Bug is reported.
Good.
You can compare anything in an if statement, so why is switch more limited?
switch has stronger requirements than a series of if statements and its uses
such extra information to create assembly code that's more efficient than a
series of if
I have function which have more than one return, and the code compile and run
but it gives rong result -I guess-, so i use tuple but the compiler can't
return tuple.
how can I return values?
why I can't return tuple?
%u:
I have function which have more than one return, and the code compile and run
but it gives rong result -I guess-, so i use tuple but the compiler can't
return tuple.
how can I return values?
why I can't return tuple?
Currently in D there are two ways to return multiple values from a
In the C standard library there are the sqrtf, cosf, sinf functions, that
return a 32 bit float. In D std.math.sqrt returns a float if the input argument
is float, but sin and cos return double even if their argument is float:
import std.math: sqrt, sin, cos;
void main() {
float x = 1.0f;
On 2011-04-20 01:35:46 +0300, %u said:
I have function which have more than one return, and the code compile and run
but it gives rong result -I guess-, so i use tuple but the compiler can't
return tuple.
how can I return values?
why I can't return tuple?
In D, tuple is not built in type, it
14 matches
Mail list logo