digitalmars.D - Can not overload template method function with const. Bug?
- "Tobias Pankrath" <tobias pankrath.net> Aug 08 2012
- kenji hara <k.hara.pg gmail.com> Aug 08 2012
- kenji hara <k.hara.pg gmail.com> Aug 08 2012
- "Tobias Pankrath" <tobias pankrath.net> Aug 08 2012
- "Tobias Pankrath" <tobias pankrath.net> Aug 08 2012
- kenji hara <k.hara.pg gmail.com> Aug 08 2012
- "Tobias Pankrath" <tobias pankrath.net> Aug 08 2012
You currently can't use Tuples with std.container.Array (Bug #8284) 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>:
You currently can't use Tuples with std.container.Array (Bug #8284)
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
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>:You currently can't use Tuples with std.container.Array (Bug #8284) 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 Hara
yesterday and within phobos directory, usingmake -f posix.mak
everything 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
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=8522
Using postfix const.
Aug 08 2012
2012/8/9 Tobias Pankrath <tobias pankrath.net>: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 Hara
within phobos directory, usingmake -f posix.mak
everything 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'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 Hara
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/1075
Thank you. Your patch works for me as well.
Aug 08 2012









kenji hara <k.hara.pg gmail.com> 