digitalmars.D.learn - const overload
- so (4/4) Sep 23 2011 Hello everyone.
- Jonathan M Davis (4/9) Sep 23 2011 That compiles fine with the lastest dmd from git. Is it not compiling wi...
- so (6/16) Sep 23 2011 It compiles fine but the result troubling, wouldn't you expect:
- Steven Schveighoffer (26/44) Sep 23 2011 steves@steve-laptop:~/testd$ cat testconst.cpp
- so (3/28) Sep 23 2011 You are right, i am confused. Sorry about that.
- Jonathan M Davis (10/32) Sep 23 2011 It uses the const version if the struct or class is const. And in neithe...
- so (3/17) Sep 23 2011 I was just testing you!
- Steven Schveighoffer (23/27) Sep 23 2011 example? I'm afraid I don't really understand the question. overloads ...
- Steven Schveighoffer (5/12) Sep 23 2011 Sorry, didn't notice the attachment...
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++?
Sep 23 2011
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 it not compiling with the latest release (dmd 2.055)? - Jonathan M Davis
Sep 23 2011
On Fri, 23 Sep 2011 23:27:02 +0300, Jonathan M Davis <jmdavisProg gmx.com> wrote:On Friday, September 23, 2011 23:19:15 so wrote:It compiles fine but the result troubling, wouldn't you expect: fun fun const as a result? This is how it works in C++.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 it not compiling with the latest release (dmd 2.055)? - Jonathan M Davis
Sep 23 2011
On Fri, 23 Sep 2011 16:35:59 -0400, so <so so.so> wrote:On Fri, 23 Sep 2011 23:27:02 +0300, Jonathan M Davis <jmdavisProg gmx.com> wrote:steves steve-laptop:~/testd$ cat testconst.cpp #include <iostream> using namespace std; struct S { S& fun() { cout << "fun" << endl; return *this; } S fun() const { cout << "fun const" << endl; return S(); } }; int main() { S a; a.fun() = a.fun(); return 0; } steves steve-laptop:~/testd$ g++ -o testconst testconst.cpp steves steve-laptop:~/testd$ ./testconst fun fun steves steve-laptop:~/testd$ Seems, um to be the same, no? -SteveOn Friday, September 23, 2011 23:19:15 so wrote:It compiles fine but the result troubling, wouldn't you expect: fun fun const as a result? This is how it works in C++.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 it not compiling with the latest release (dmd 2.055)? - Jonathan M Davis
Sep 23 2011
On Fri, 23 Sep 2011 23:44:52 +0300, Steven Schveighoffer <schveiguy yahoo.com> wrote:steves steve-laptop:~/testd$ cat testconst.cpp #include <iostream> using namespace std; struct S { S& fun() { cout << "fun" << endl; return *this; } S fun() const { cout << "fun const" << endl; return S(); } }; int main() { S a; a.fun() = a.fun(); return 0; } steves steve-laptop:~/testd$ g++ -o testconst testconst.cpp steves steve-laptop:~/testd$ ./testconst fun fun steves steve-laptop:~/testd$ Seems, um to be the same, no? -SteveYou are right, i am confused. Sorry about that.
Sep 23 2011
On Friday, September 23, 2011 23:35:59 so wrote:On Fri, 23 Sep 2011 23:27:02 +0300, Jonathan M Davis <jmdavisProg gmx.com> 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 called? How would it know to call that one instead of the mutable one? I don't know how it could work any other way. I would have thought that it would be exactly the same in C++, but I don't overload on constness very often in either language, so I'm not necessarily familiar with all of the ins and outs of why C++ picks const over mutable in such cases. - Jonathan M DavisOn Friday, September 23, 2011 23:19:15 so wrote:It compiles fine but the result troubling, wouldn't you expect: fun fun const as a result? This is how it works in C++.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 it not compiling with the latest release (dmd 2.055)? - Jonathan M Davis
Sep 23 2011
On Fri, 23 Sep 2011 23:44:41 +0300, Jonathan M Davis <jmdavisProg gmx.com> 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 called? How would it know to call that one instead of the mutable one? I don't know how it could work any other way. I would have thought that it would be exactly the same in C++, but I don't overload on constness very often in either language, so I'm not necessarily familiar with all of the ins and outs of why C++ picks const over mutable in such cases. - Jonathan M DavisI was just testing you!
Sep 23 2011
On Fri, 23 Sep 2011 16:19:15 -0400, so <so so.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. overloads based on const/immutable are supported: struct S { void foo() { writeln("mutable");} void foo() const { writeln("const");} void foo() immutable { writeln("immutable");} } void main() { S s; immutable(S) s2; const(S) s3; s.foo(); s2.foo(); s3.foo(); } outputs: mutable immutable const -Steve
Sep 23 2011
On Fri, 23 Sep 2011 16:27:23 -0400, Steven Schveighoffer <schveiguy yahoo.com> wrote:On Fri, 23 Sep 2011 16:19:15 -0400, so <so so.so> wrote:Sorry, didn't notice the attachment... re-examining... -SteveHello 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.
Sep 23 2011