digitalmars.D - Can not overload template method function with const. Bug?
- Tobias Pankrath (15/15) Aug 08 2012 You currently can't use Tuples with std.container.Array (Bug
- kenji hara (13/24) Aug 08 2012 In the declaration of std.typecons.Tuple:
- Tobias Pankrath (9/22) Aug 08 2012 That's exactly what I've tried first. Using a git clone from
- kenji hara (19/45) Aug 08 2012 I've tried following code now, and it is exactly the bug 8522.
- Tobias Pankrath (2/20) Aug 08 2012 Thank you. Your patch works for me as well.
- kenji hara (4/35) Aug 08 2012 I found a dmd bug. Is this the bug which you have seen?
- Tobias Pankrath (2/4) Aug 08 2012 Using postfix const.
You currently can't use Tuples with std.container.Array (Bug To fix this, I tried to overload the opEquals(R)(R rhs) of Tuple with a const version opEquals(R)(R rhs) const. But the compiler does not use the overload if opEquals is called on a const tuple instance. See this thread in d.learn http://forum.dlang.org/thread/vghlctzlpqxhoeojqqxt forum.dlang.org The orignal bug is solved, if you mark the current opEquals const, but I don't know if this would brake code outside of phobos, so I tried the overload. Coming to the question: Is it a bug that the const overload is not considered and what is the correct way to fix std.typecons.Tuple?
Aug 08 2012
In the declaration of std.typecons.Tuple: bool opEquals(R)(R rhs) if (isTuple!R) { // [snip] } bool opEquals(R)(R rhs) const if (isTuple!R) { // same as non-const version } Adding const version works correctly. What's the problem? Kenji Hara 2012/8/8 Tobias Pankrath <tobias pankrath.net>:To fix this, I tried to overload the opEquals(R)(R rhs) of Tuple with a const version opEquals(R)(R rhs) const. But the compiler does not use the overload if opEquals is called on a const tuple instance. See this thread in d.learn http://forum.dlang.org/thread/vghlctzlpqxhoeojqqxt forum.dlang.org The orignal bug is solved, if you mark the current opEquals const, but I don't know if this would brake code outside of phobos, so I tried the overload. Coming to the question: Is it a bug that the const overload is not considered and what is the correct way to fix std.typecons.Tuple?
Aug 08 2012
On Wednesday, 8 August 2012 at 15:01:23 UTC, kenji hara wrote:In the declaration of std.typecons.Tuple: bool opEquals(R)(R rhs) if (isTuple!R) { // [snip] } bool opEquals(R)(R rhs) const if (isTuple!R) { // same as non-const version } Adding const version works correctly. What's the problem? Kenji HaraThat's exactly what I've tried first. Using a git clone from yesterday and within phobos directory, usingmake -f posix.makeverything works. Now I'm adding the const version of opEquals and I get: http://pastebin.com/akRdFfAJ But it's similar with the reduced example from the thread in d.learn. Does that work for you? I'm using dmd cef1bbfdcd9282934ff6f1b07617254753334799 and phobos 90eb9313030340dc274d2fd82144a7f30d0e4ae5
Aug 08 2012
2012/8/9 Tobias Pankrath <tobias pankrath.net>:On Wednesday, 8 August 2012 at 15:01:23 UTC, kenji hara wrote:I've tried following code now, and it is exactly the bug 8522. struct Point { bool opEquals(R)(R rhs) { return true; } bool opEquals(R)(R rhs) const { return true; } } void main() { Point mp; const Point cp; assert(mp == mp); assert(mp == cp); assert(cp == mp); assert(cp == cp); } This code doesn't work with current git head of dmd, but works with my patch. https://github.com/D-Programming-Language/dmd/pull/1075 Kenji HaraIn the declaration of std.typecons.Tuple: bool opEquals(R)(R rhs) if (isTuple!R) { // [snip] } bool opEquals(R)(R rhs) const if (isTuple!R) { // same as non-const version } Adding const version works correctly. What's the problem? Kenji HaraThat's exactly what I've tried first. Using a git clone from yesterday and within phobos directory, usingmake -f posix.makeverything works. Now I'm adding the const version of opEquals and I get: http://pastebin.com/akRdFfAJ But it's similar with the reduced example from the thread in d.learn. Does that work for you?
Aug 08 2012
On Wednesday, 8 August 2012 at 15:54:43 UTC, kenji hara wrote:I've tried following code now, and it is exactly the bug 8522. struct Point { bool opEquals(R)(R rhs) { return true; } bool opEquals(R)(R rhs) const { return true; } } void main() { Point mp; const Point cp; assert(mp == mp); assert(mp == cp); assert(cp == mp); assert(cp == cp); } This code doesn't work with current git head of dmd, but works with my patch. https://github.com/D-Programming-Language/dmd/pull/1075Thank you. Your patch works for me as well.
Aug 08 2012
I found a dmd bug. Is this the bug which you have seen? http://d.puremagic.com/issues/show_bug.cgi?id=8522 Kenji Hara 2012/8/9 kenji hara <k.hara.pg gmail.com>:In the declaration of std.typecons.Tuple: bool opEquals(R)(R rhs) if (isTuple!R) { // [snip] } bool opEquals(R)(R rhs) const if (isTuple!R) { // same as non-const version } Adding const version works correctly. What's the problem? Kenji Hara 2012/8/8 Tobias Pankrath <tobias pankrath.net>:To fix this, I tried to overload the opEquals(R)(R rhs) of Tuple with a const version opEquals(R)(R rhs) const. But the compiler does not use the overload if opEquals is called on a const tuple instance. See this thread in d.learn http://forum.dlang.org/thread/vghlctzlpqxhoeojqqxt forum.dlang.org The orignal bug is solved, if you mark the current opEquals const, but I don't know if this would brake code outside of phobos, so I tried the overload. Coming to the question: Is it a bug that the const overload is not considered and what is the correct way to fix std.typecons.Tuple?
Aug 08 2012
On Wednesday, 8 August 2012 at 15:25:04 UTC, kenji hara wrote:I found a dmd bug. Is this the bug which you have seen? http://d.puremagic.com/issues/show_bug.cgi?id=8522Using postfix const.
Aug 08 2012