Re: How to const-overload opEquals(R)(R rhs)?

2012-08-07 Thread Jonathan M Davis
On Tuesday, August 07, 2012 15:40:18 Tobias Pankrath wrote: > Hey, > > let's say I have a simple struct and I want to give it an > opEquals like this. > > struct Point > { > int x, y; > bool opEquals(R)(R rhs) { return x == rhs.x && y == rhs.y; } > } > > > With this I can't call opEquals on con

Re: How to const-overload opEquals(R)(R rhs)?

2012-08-07 Thread Tobias Pankrath
On Tuesday, 7 August 2012 at 16:46:04 UTC, Ali Çehreli wrote: On 08/07/2012 06:40 AM, Tobias Pankrath wrote: > bool opEquals(R)(R rhs) { return x == rhs.x && y == rhs.y; } > bool opEquals(R)(R rhs) const { return x == rhs.x && y == rhs.y; } I strongly recommend that only the const version shoul

Re: How to const-overload opEquals(R)(R rhs)?

2012-08-07 Thread Ali Çehreli
On 08/07/2012 06:40 AM, Tobias Pankrath wrote: > bool opEquals(R)(R rhs) { return x == rhs.x && y == rhs.y; } > bool opEquals(R)(R rhs) const { return x == rhs.x && y == rhs.y; } I strongly recommend that only the const version should be defined. That would work on both mutable and immutable ob

Re: How to const-overload opEquals(R)(R rhs)?

2012-08-07 Thread David
Really? It compiles: http://dpaste.dzfl.pl/e0470f9a

How to const-overload opEquals(R)(R rhs)?

2012-08-07 Thread Tobias Pankrath
Hey, let's say I have a simple struct and I want to give it an opEquals like this. struct Point { int x, y; bool opEquals(R)(R rhs) { return x == rhs.x && y == rhs.y; } } With this I can't call opEquals on const instances of Point, because dmd says bug.d(13): Error: function bug.P

Re: const overload

2011-09-23 Thread so
On Fri, 23 Sep 2011 23:44:41 +0300, Jonathan M Davis wrote: It uses the const version if the struct or class is const. And in neither case in your program is it const. It's mutable in both, so the mutable overload is the one that gets called in both places. Why would the const version get

Re: const overload

2011-09-23 Thread so
On Fri, 23 Sep 2011 23:44:52 +0300, Steven Schveighoffer wrote: steves@steve-laptop:~/testd$ cat testconst.cpp #include using namespace std; struct S { S& fun() { cout << "fun" << endl; return *this; } S fun() const { cout << "fun const" << endl;

Re: const overload

2011-09-23 Thread Steven Schveighoffer
On Fri, 23 Sep 2011 16:35:59 -0400, so wrote: On Fri, 23 Sep 2011 23:27:02 +0300, Jonathan M Davis wrote: On Friday, September 23, 2011 23:19:15 so wrote: Hello everyone. I asked this a few times with no response. Could anyone explain me what is the rational behind this? Why it won't dis

Re: const overload

2011-09-23 Thread Steven Schveighoffer
On Fri, 23 Sep 2011 16:27:23 -0400, Steven Schveighoffer wrote: On Fri, 23 Sep 2011 16:19:15 -0400, so wrote: Hello everyone. I asked this a few times with no response. Could anyone explain me what is the rational behind this? Why it won't distinguish mutable overload from immutable as in

Re: const overload

2011-09-23 Thread Jonathan M Davis
On Friday, September 23, 2011 23:35:59 so wrote: > On Fri, 23 Sep 2011 23:27:02 +0300, Jonathan M Davis > > wrote: > > On Friday, September 23, 2011 23:19:15 so wrote: > >> Hello everyone. > >> > >> I asked this a few times with no response. > >> Could anyone explain me what is the rational behi

Re: const overload

2011-09-23 Thread so
On Fri, 23 Sep 2011 23:27:02 +0300, Jonathan M Davis wrote: On Friday, September 23, 2011 23:19:15 so wrote: Hello everyone. I asked this a few times with no response. Could anyone explain me what is the rational behind this? Why it won't distinguish mutable overload from immutable as in C+

Re: const overload

2011-09-23 Thread Steven Schveighoffer
On Fri, 23 Sep 2011 16:19:15 -0400, so wrote: Hello everyone. I asked this a few times with no response. Could anyone explain me what is the rational behind this? Why it won't distinguish mutable overload from immutable as in C++? example? I'm afraid I don't really understand the question.

Re: const overload

2011-09-23 Thread Jonathan M Davis
On Friday, September 23, 2011 23:19:15 so wrote: > Hello everyone. > > I asked this a few times with no response. > Could anyone explain me what is the rational behind this? > Why it won't distinguish mutable overload from immutable as in C++? That compiles fine with the lastest dmd from git. Is

const overload

2011-09-23 Thread so
Hello everyone. I asked this a few times with no response. Could anyone explain me what is the rational behind this? Why it won't distinguish mutable overload from immutable as in C++? test2.d Description: Binary data