Re: is operator for structures?

2012-05-10 Thread Jacob Carlborg
On 2012-05-10 00:05, H. S. Teoh wrote: On Wed, May 09, 2012 at 05:04:59PM -0400, Steven Schveighoffer wrote: Is there a unicode glyph for fist pump? :) [...] U+270A? :-) Haha :) -- /Jacob Carlborg

Re: is operator for structures?

2012-05-09 Thread bearophile
Gor Gyolchanyan: My question is, why not allow is operator to be overloadable for structures? Or why the bad D compiler doesn't statically refuse the code like: bool opBinary(string op : is)(typeof(null)) Bye, bearophile

Re: is operator for structures?

2012-05-09 Thread Gor Gyolchanyan
Because the opBinary is a perfectly valid method. The inability to overload is only affects the rewrite of A is B to A.opBinart!`is`(B). On Wed, May 9, 2012 at 5:46 PM, bearophile bearophileh...@lycos.com wrote: Gor Gyolchanyan: My question is, why not allow is operator to be overloadable for

Re: is operator for structures?

2012-05-09 Thread bearophile
Gor Gyolchanyan: Because the opBinary [...] Thank for your answer, but I don't carte of why the D compiler accepts that. I only care about the D compiler statically refusing that. Bye, bearophile

Re: is operator for structures?

2012-05-09 Thread Don Clugston
On 09/05/12 16:13, bearophile wrote: Gor Gyolchanyan: Because the opBinary [...] Thank for your answer, but I don't carte of why the D compiler accepts that. I only care about the D compiler statically refusing that. Bye, bearophile I think you're asking for opBinary to be a keyword. If

Re: is operator for structures?

2012-05-09 Thread Steven Schveighoffer
On Wed, 09 May 2012 10:13:01 -0400, bearophile bearophileh...@lycos.com wrote: Gor Gyolchanyan: Because the opBinary [...] Thank for your answer, but I don't carte of why the D compiler accepts that. I only care about the D compiler statically refusing that. This also works too: int

Re: is operator for structures?

2012-05-09 Thread Gor Gyolchanyan
I didn't know structs actually have an is operator. Good to know, there's a way to memcmp them this way. But being able to overload it wouldn't do any damage. The overloader of is should clearly know, that is is an identity check and not an arbitrary domain-specific equality check. Overloading is

Re: is operator for structures?

2012-05-09 Thread Gor Gyolchanyan
If is was overloadable, one could make a legitimate reference types via structs. The opAssign would change the reference, opEquals would call the opEquals of the referred object, opBinary(string op : `is`) would compare the references... Just like classes. On Wed, May 9, 2012 at 8:13 PM, Steven

Re: is operator for structures?

2012-05-09 Thread Steven Schveighoffer
On Wed, 09 May 2012 12:17:30 -0400, Gor Gyolchanyan gor.f.gyolchan...@gmail.com wrote: I didn't know structs actually have an is operator. Good to know, there's a way to memcmp them this way. But being able to overload it wouldn't do any damage. The overloader of is should clearly know, that

Re: is operator for structures?

2012-05-09 Thread Steven Schveighoffer
On Wed, 09 May 2012 12:21:05 -0400, Gor Gyolchanyan gor.f.gyolchan...@gmail.com wrote: If is was overloadable, one could make a legitimate reference types via structs. The opAssign would change the reference, opEquals would call the opEquals of the referred object, opBinary(string op : `is`)

Re: is operator for structures?

2012-05-09 Thread Gor Gyolchanyan
Yeah, that's what I did. I replaced it with opEquals(typeof(null)). On Wed, May 9, 2012 at 8:45 PM, Steven Schveighoffer schvei...@yahoo.com wrote: On Wed, 09 May 2012 12:17:30 -0400, Gor Gyolchanyan gor.f.gyolchan...@gmail.com wrote: I didn't know structs actually have an is operator. Good

Re: is operator for structures?

2012-05-09 Thread Gor Gyolchanyan
Btw, I noticed how classes have two different comparison operators (one for the reference and one for the object), while they have only one assignment operator (for the reference only), I think having two assignment operators would be very good for a number of cases. Combined with a final class

Re: is operator for structures?

2012-05-09 Thread Jacob Carlborg
On 2012-05-09 18:13, Steven Schveighoffer wrote: This also works too: int opBinary(string s: booya!)(...) We could create new operators :) -- /Jacob Carlborg

Re: is operator for structures?

2012-05-09 Thread Steven Schveighoffer
On Wed, 09 May 2012 16:25:35 -0400, Jacob Carlborg d...@me.com wrote: On 2012-05-09 18:13, Steven Schveighoffer wrote: This also works too: int opBinary(string s: booya!)(...) We could create new operators :) Is there a unicode glyph for fist pump? :) -Steve

Re: is operator for structures?

2012-05-09 Thread H. S. Teoh
On Wed, May 09, 2012 at 05:04:59PM -0400, Steven Schveighoffer wrote: On Wed, 09 May 2012 16:25:35 -0400, Jacob Carlborg d...@me.com wrote: On 2012-05-09 18:13, Steven Schveighoffer wrote: This also works too: int opBinary(string s: booya!)(...) We could create new operators :)

Re: is operator for structures?

2012-05-09 Thread Matt Soucy
On 05/09/2012 06:05 PM, H. S. Teoh wrote: On Wed, May 09, 2012 at 05:04:59PM -0400, Steven Schveighoffer wrote: On Wed, 09 May 2012 16:25:35 -0400, Jacob Carlborgd...@me.com wrote: On 2012-05-09 18:13, Steven Schveighoffer wrote: This also works too: int opBinary(string s: booya!)(...)

Re: is operator for structures?

2012-05-09 Thread Gor Gyolchanyan
I think it would be a unary prefix operator, which returns the operand's copy, but with double the storage, having the second half - wasted. :-D On Thu, May 10, 2012 at 2:33 AM, Matt Soucy mso...@csh.rit.edu wrote: On 05/09/2012 06:05 PM, H. S. Teoh wrote: On Wed, May 09, 2012 at 05:04:59PM