Re: How to implement a copy

2010-03-18 Thread Paul D. Anderson
bearophile Wrote: > Paul D. Anderson: > > Or is this a distinction without a difference? > > For POD structs like this one I suggest to implement nothing, and just let > the compiler copy the struct by itself. > If the struct is not a POD then I like the dup property. Each of those other > ways

Re: [D1] struct opEquals questions

2010-03-18 Thread bearophile
Inside free functions there can be a locally defined compile-time boolean constant like __used_return. If you use this constant inside a function the compiler creates two versions of the function that share the same static variables (if the function is a template then each pair of instantiated

Re: How to implement a copy

2010-03-18 Thread bearophile
Paul D. Anderson: > Or is this a distinction without a difference? For POD structs like this one I suggest to implement nothing, and just let the compiler copy the struct by itself. If the struct is not a POD then I like the dup property. Each of those other ways can be OK, according to the synt

Re: [D1] struct opEquals questions

2010-03-18 Thread qwerty
bearophile Wrote: >> (time ago I have suggested for a compile time flag that's defined inside >> functions to know if their result is used, to avoid computing it in some >> situations, turning the single function in a kind of templated function, but >> I am not sure it can work well if you have

Re: [D1] struct opEquals questions

2010-03-18 Thread bearophile
qwerty: > For a function without any side effects, it shouldn't be a problem.. I think > :) Ignoring the return value of a function without side effects (in D2 pure functions or nothrow pure functions) has to be an error. I even have a bug report for this, because it's the same situation as an

How to implement a copy

2010-03-18 Thread Paul D. Anderson
If I'm implementing a struct and want to provide for duplication, is there a standard way to implement this? Here's an example: //--- struct S { // members of the struct -- three integer values int a; int b; int c; // here's a copy constructor

Re: [D1] struct opEquals questions

2010-03-18 Thread qwerty
bearophile Wrote: > qwerty: > > If I return *this, I should also provide the *S version of opEquals? > > If you don't provide a necessary operator the compiler complaints. > > > > What happens with the return value if it isn't used? > > The function is one and it doesn't change, it has to be

Re: [D1] struct opEquals questions

2010-03-18 Thread bearophile
qwerty: > If I return *this, I should also provide the *S version of opEquals? If you don't provide a necessary operator the compiler complaints. > What happens with the return value if it isn't used? The function is one and it doesn't change, it has to be the same for everyone that calls it

Re: system mkdir

2010-03-18 Thread noboy
There was a soft link /bin/sh -> dash I have change this to bash, and now all went fine. Thank you Steven Schveighoffer Wrote: > On Thu, 18 Mar 2010 09:28:06 -0400, noboy wrote: > > > I was little bit surprise because > > mkdir -p dmd-2/usr/{bin,lib,src/phobos2,share/man > > do the right thing

Re: system mkdir

2010-03-18 Thread Steven Schveighoffer
On Thu, 18 Mar 2010 09:28:06 -0400, noboy wrote: I was little bit surprise because mkdir -p dmd-2/usr/{bin,lib,src/phobos2,share/man do the right thing. When you do that, you are using your shell. The shell actually does the argument expansion, not mkdir. So the question to answer is, doe

Re: system mkdir

2010-03-18 Thread noboy
I was little bit surprise because mkdir -p dmd-2/usr/{bin,lib,src/phobos2,share/man do the right thing. But if i make mkdir -p "dmd-2/usr/{bin,lib,src/phobos2,share/man" it's wrong. So i have think the system command wrap quotes about the command. Perl have the same behaviour. Thank you for you

Re: [D1] struct opEquals questions

2010-03-18 Thread qwerty
bearophile Wrote: > qwerty: > > My opEquals takes an Vec2 and not a *Vec2, is this wrong? > > It's OK. D1 docs say: > Structs and unions (hereafter just called structs) can provide a member > function: > int opEquals(S s) > or: > int opEquals(S* s) > > > > Why is return value of the rotate fun

Re: [D1] struct opEquals questions

2010-03-18 Thread qwerty
Lars T. Kyllingstad Wrote: > qwerty wrote: > > In my unittest I tried to test out my rotate function. > > assert(Vec2(1,2).rotate(90) == Vec(-2,1)); > > But I got these compile errors: > > vector.d(156): Error: function vector.Vec.opEquals (Vec) does not match > > parameter types (void) > > vecto

Re: [D1] modulo on neg integer

2010-03-18 Thread qwerty
qwerty Wrote: > bearophile Wrote: > > > qwerty: > > > If memory serves me right, module is undefined on negative integers. > > > > I think it's defined in D (but it's defined badly). > Got url ? :) Yeah, here http://www.digitalmars.com/d/1.0/expression.html#MulExpression

Re: [D1] modulo on neg integer

2010-03-18 Thread qwerty
Don Wrote: > qwerty wrote: > > If memory serves me right, module is undefined on negative integers. > > int i = -2; > > i%=10; // i=undefined? > > It's not undefined. x%y always has the sign of x, so i will be -2. > > This always holds: > x == y * (x/y) + (x%y); > And since D uses truncated div

Re: system mkdir

2010-03-18 Thread Steven Schveighoffer
On Thu, 18 Mar 2010 06:25:20 -0400, noboy wrote: Hello, import std.stdio; import std.process; import std.string; void main() { string debPackage="dmd-2"; int dmdVersion=2; auto path = format("%s/usr/{bin,lib,src/phobos%d,share/man}",debPackage,dmdVersion); system("mkdir -p

Re: [D1] modulo on neg integer

2010-03-18 Thread qwerty
bearophile Wrote: > qwerty: > > If memory serves me right, module is undefined on negative integers. > > I think it's defined in D (but it's defined badly). Got url ? :) > > > > int i = -2; > > i%=10; // i=undefined? > > What should I use instead to get i definitely equal to 7? > > D outputs -

Re: [D1] struct opEquals questions

2010-03-18 Thread Lars T. Kyllingstad
qwerty wrote: In my unittest I tried to test out my rotate function. assert(Vec2(1,2).rotate(90) == Vec(-2,1)); But I got these compile errors: vector.d(156): Error: function vector.Vec.opEquals (Vec) does not match parameter types (void) vector.d(156): Error: cannot implicitly convert expressio

Re: [D1] struct opEquals questions

2010-03-18 Thread bearophile
qwerty: > My opEquals takes an Vec2 and not a *Vec2, is this wrong? It's OK. D1 docs say: Structs and unions (hereafter just called structs) can provide a member function: int opEquals(S s) or: int opEquals(S* s) > Why is return value of the rotate function compared and not the rotated > struc

Re: [D1] modulo on neg integer

2010-03-18 Thread Don
qwerty wrote: If memory serves me right, module is undefined on negative integers. int i = -2; i%=10; // i=undefined? It's not undefined. x%y always has the sign of x, so i will be -2. This always holds: x == y * (x/y) + (x%y); And since D uses truncated division, the result follows. This beh

[D1] struct opEquals questions

2010-03-18 Thread qwerty
In my unittest I tried to test out my rotate function. assert(Vec2(1,2).rotate(90) == Vec(-2,1)); But I got these compile errors: vector.d(156): Error: function vector.Vec.opEquals (Vec) does not match parameter types (void) vector.d(156): Error: cannot implicitly convert expression (opCall(1,2).

Re: [D1] modulo on neg integer

2010-03-18 Thread bearophile
qwerty: > If memory serves me right, module is undefined on negative integers. I think it's defined in D (but it's defined badly). > int i = -2; > i%=10; // i=undefined? > What should I use instead to get i definitely equal to 7? D outputs -2, Python outputs 8. It's not easy to find a language

[D1] modulo on neg integer

2010-03-18 Thread qwerty
If memory serves me right, module is undefined on negative integers. int i = -2; i%=10; // i=undefined? What should I use instead to get i definitely equal to 7? On a sidenote, where can I read about operation order/definitions? Like i++, ++i and i%10 not changing i etc.

system mkdir

2010-03-18 Thread noboy
Hello, import std.stdio; import std.process; import std.string; void main() { string debPackage="dmd-2"; int dmdVersion=2; auto path = format("%s/usr/{bin,lib,src/phobos%d,share/man}",debPackage,dmdVersion); system("mkdir -p " ~ path); } The result: dmd-2/usr/{bin,lib,src it