Re: ref is pointer sugar?

2010-08-06 Thread Pluto
== Quote from Jacob Carlborg (d...@me.com)'s article > On 2010-08-06 15:33, Pluto wrote: > > == Quote from Steven Schveighoffer (schvei...@yahoo.com)'s article > >> On Fri, 06 Aug 2010 08:51:31 -0400, Pluto wrote: > >>> Are these equivalent? > >>> > >>> S s;//struct > >>> > >>> void f(ref S s){s.x

Re: ref is pointer sugar?

2010-08-06 Thread Jacob Carlborg
On 2010-08-06 15:33, Pluto wrote: == Quote from Steven Schveighoffer (schvei...@yahoo.com)'s article On Fri, 06 Aug 2010 08:51:31 -0400, Pluto wrote: Are these equivalent? S s;//struct void f(ref S s){s.x++;} f(s); void f2(S* s){(*s).x++;} f2(&s); They are pretty much equivalent. I think

Re: ref is pointer sugar?

2010-08-06 Thread Pluto
== Quote from Steven Schveighoffer (schvei...@yahoo.com)'s article > On Fri, 06 Aug 2010 08:51:31 -0400, Pluto wrote: > > Are these equivalent? > > > > S s;//struct > > > > void f(ref S s){s.x++;} > > f(s); > > > > void f2(S* s){(*s).x++;} > > f2(&s); > They are pretty much equivalent. I think th

Re: ref is pointer sugar?

2010-08-06 Thread Pluto
== Quote from Steven Schveighoffer (schvei...@yahoo.com)'s article > On Fri, 06 Aug 2010 08:51:31 -0400, Pluto wrote: > > Are these equivalent? > > > > S s;//struct > > > > void f(ref S s){s.x++;} > > f(s); > > > > void f2(S* s){(*s).x++;} > > f2(&s); > They are pretty much equivalent. I think th

Re: ref is pointer sugar?

2010-08-06 Thread Steven Schveighoffer
On Fri, 06 Aug 2010 08:51:31 -0400, Pluto wrote: Are these equivalent? S s;//struct void f(ref S s){s.x++;} f(s); void f2(S* s){(*s).x++;} f2(&s); They are pretty much equivalent. I think the code generated actually will be exactly the same. However, the compiler treats ref differently

ref is pointer sugar?

2010-08-06 Thread Pluto
Are these equivalent? S s;//struct void f(ref S s){s.x++;} f(s); void f2(S* s){(*s).x++;} f2(&s); If so, why is it stated that ref is very rarely used? It looks like something I would use a lot with structures.

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

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; } tem

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 > > - > >

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 New

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 assert(IsPointe

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 > } > > >

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: templa