Re: How to implement a copy

2010-03-20 Thread Ali Çehreli
� wrote: this(this) is the copy constructor, I think. this(this) is not the copy constructor. It is post-blit, which is useful for when corrections need to be done after the automatic blitting: http://digitalmars.com/d/2.0/struct.html#StructPostblit Ali

is pointer

2010-03-20 Thread bearophile
(I am looking for rough corners in D, or in my knowledge of D.) In this page: http://www.digitalmars.com/d/2.0/templates-revisited.html In the section Template Parameters there is written: P:P*, // P must be a pointer type - So I have written this D2 program:

Re: system mkdir

2010-03-20 Thread Spacen Jasset
noboy wrote: 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 nob...@nowhere.com wrote: I was little bit surprise because mkdir -p dmd-2/usr/{bin,lib,src/phobos2,share/man

Re: is pointer

2010-03-20 Thread Moritz Warning
On Fri, 19 Mar 2010 19:29:24 -0400, bearophile wrote: (I am looking for rough corners in D, or in my knowledge of D.) [..] template IsPointer1(T) { enum bool IsPointer1 = is(T : T*); } void main() { int* ptr; static assert(IsPointer1!(typeof(ptr))); // Err } But it

Confused about const

2010-03-20 Thread Paul D. Anderson
I created a struct, call it S, and some functions that operate on S. But I'm confused about when const is useful. Being an old Java programmer, I use 'const' the same as I used 'final' in Java. So most of my functions look like this: S for(const S a, const S b) { S x = a; S y = b;

Re: Confused about const

2010-03-20 Thread bearophile
Paul D. Anderson: I created a struct, call it S, and some functions that operate on S. But I'm confused about when const is useful. Being an old Java programmer, I use 'const' the same as I used 'final' in Java. So most of my functions look like this: S for(const S a, const S b) {

Re: Confused about const

2010-03-20 Thread bearophile
Paul D. Anderson: S x = cast(S) a; S y = cast(S) b; In Java (especially old Java) casts may be common, but in D they are something that has to be used with care, don't cast away things carelessly :-) Bye, bearophile

Re: Confused about const

2010-03-20 Thread Paul D. Anderson
bearophile Wrote: Paul D. Anderson: I created a struct, call it S, and some functions that operate on S. But I'm confused about when const is useful. Being an old Java programmer, I use 'const' the same as I used 'final' in Java. So most of my functions look like this: S

Re: Confused about const

2010-03-20 Thread Paul D. Anderson
bearophile Wrote: Paul D. Anderson: S x = cast(S) a; S y = cast(S) b; In Java (especially old Java) casts may be common, but in D they are something that has to be used with care, don't cast away things carelessly :-) Bye, bearophile I realize that casting is a last resort

Re: is pointer

2010-03-20 Thread Ellery Newcomer
On 03/19/2010 07:53 PM, Moritz Warning wrote: On Fri, 19 Mar 2010 19:29:24 -0400, bearophile wrote: (I am looking for rough corners in D, or in my knowledge of D.) [..] template IsPointer1(T) { enum bool IsPointer1 = is(T : T*); } void main() { int* ptr; static

Re: is pointer

2010-03-20 Thread bearophile
Moritz Warning: I think the problem is that is(T : T*) becomes is(int* : int**) and that's false. Thank you, you can be right. So D docs are wrong, or that syntax has a semantic bug, or I have not understood the situation yet. If someone else has ideas I'm all ears. - Ellery

Re: Confused about const

2010-03-20 Thread biozic
My guess is that: struct S { int x; int[] a; } S foo(const S b) { foo makes the promise that b's members won't change: so 'b.x' is implicitely const(int) and 'b.a' is implicitely const(int[]). S other = b; Here you assign 'b.x', which is const(int), to 'other.x', which is int.

Re: Confused about const

2010-03-20 Thread bearophile
biozic: I'm not sure if this is completely right nor if I'm completely clear, though... :) I think you are right. In practice to copy something const to something that's not const you need a deep copy function, because inside the array there can be other arrays that are const, etc.

Re: Confused about const

2010-03-20 Thread bearophile
Transitive const requires transitive copy, it's easy :-) Or when possible, you don't copy it, just return it. Bye, bearophile

Re: Confused about const

2010-03-20 Thread bearophile
So the question here is: do you know if there are important use cases for a shallow_const attribute? Bye, bearophile

Re: is pointer

2010-03-20 Thread Daniel Keep
bearophile wrote: (I am looking for rough corners in D, or in my knowledge of D.) In this page: http://www.digitalmars.com/d/2.0/templates-revisited.html In the section Template Parameters there is written: P:P*, // P must be a pointer type - So I have

Re: Confused about const

2010-03-20 Thread bearophile
Paul D. Anderson: My struct has a dynamic array as a member -- that seems to be the problem. This code doesn't compile: struct S { int x; int[] a; } S foo(const S b) { S other = b; return other; } void main() {} This compiles, oh joy: struct S { int x; int[] a;

Re: Confused about const

2010-03-20 Thread Steven Schveighoffer
On Fri, 19 Mar 2010 20:58:21 -0400, Paul D. Anderson paul.d.removet...@comcast.andthis.net wrote: I created a struct, call it S, and some functions that operate on S. But I'm confused about when const is useful. Being an old Java programmer, I use 'const' the same as I used 'final' in

Re: Confused about const

2010-03-20 Thread Paul D. Anderson
After further review, I now realize that the right way (for me) to do this is to add a .dup property. So instead of S foo(const S s) { S other; other = s; } or S foo(const S s) { S other = S(s); return other; } which didn't look right to me, I can write S foo(const S s) {

Re: system mkdir

2010-03-20 Thread Jesse Phillips
Spacen Jasset wrote: then presumably the syntax you are using is a bashism?. You could also say something like: system(bash mkdir -p ~ path); Messing with your sh symlink may have some undesired consequences. Actually, not messing with it will have undesired consequences. Lots of

Re: Confused about const

2010-03-20 Thread Don
bearophile wrote: Operator overloading in D2 is not an easy thing, it needs training. (That's why I have recently asked for the compiler to be strict to avoid wrong usages of the operator overloading.) I think the problem is really that it's still very buggy. In particular, opAssign seems

Re: Confused about const

2010-03-20 Thread bearophile
Paul D. Anderson: After further review, I now realize that the right way (for me) to do this is to add a .dup property. Steven Schveighoffer has given you quite good answers. A dup is generally not enough, because what you dup can have other immutable references nested inside. Dup is not a

Re: is pointer

2010-03-20 Thread bearophile
Daniel Keep: You do realise that Template Parameters are a completely different thing to is expressions, right? Nope. And from the other answers by Moritz and Ellery it seems I am not alone :-) You are right, this works: template IsPointer1(T:T*) { enum bool IsPointer1 = true; } template

Re: Confused about const

2010-03-20 Thread bearophile
Don: I think the problem is really that it's still very buggy. In particular, opAssign seems pretty defective. More importantly, struct constructors, post blit, and struct destructors are still quite badly broken. You are right, but in my opinion it's not just a matter of bugs. To solve real

Re: system mkdir

2010-03-20 Thread noboy noboy
Jesse Phillips Wrote: Spacen Jasset wrote: then presumably the syntax you are using is a bashism?. You could also say something like: system(bash mkdir -p ~ path); Messing with your sh symlink may have some undesired consequences. Actually, not messing with it will have

Re: is pointer

2010-03-20 Thread Jacob Carlborg
On 2010-03-20 00.29, bearophile wrote: (I am looking for rough corners in D, or in my knowledge of D.) In this page: http://www.digitalmars.com/d/2.0/templates-revisited.html In the section Template Parameters there is written: P:P*, // P must be a pointer type - So

Returning this from a const member

2010-03-20 Thread Robert Clipsham
According to http://digitalmars.com/d/2.0/const3.html: Const member functions are functions that are not allowed to change any part of the object through the member function's this reference. With the following code: class Foo { Foo myFoo() const {

Re: Returning this from a const member

2010-03-20 Thread Robert Clipsham
On 21/03/10 00:18, bearophile wrote: Robert Clipsham: Why is this? It's not a hard question. This code compiles: class Foo { const(Foo) myFoo() const { return this; } } void main() { auto f = new Foo; } It's just in a const function the this is const, so if you want