Thread overview | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
May 10, 2010 opAddAssign still works | ||||
---|---|---|---|---|
| ||||
I just made a startling discovery: the old operator overload routines still work in 2.045 Is this intended? struct S { int x; S opAddAssign(ref const S other) { x += other.x; return this; } } void foo(S s) { s += s; } generates no error. And in fact, neither does this: struct S { int x; S opAddAssign(ref const S other) { x += other.x; return this; } S opOpAssign(string op)(ref const S other) if (op == "+=") { static assert(0, "fail!"); } } void foo(S s) { s += s; } But if I only have the template version, it does use the template. -Steve |
May 10, 2010 Re: opAddAssign still works | ||||
---|---|---|---|---|
| ||||
Posted in reply to Steven Schveighoffer | Steven Schveighoffer wrote:
> I just made a startling discovery: the old operator overload routines still work in 2.045
>
> Is this intended?
I don't know, but I am happy that they still work. I haven't gotten around to changing my code to use the new syntax yet. :)
I hope the old syntax remains as a deprecated feature and stays supported for the next 15 years or so... :)
Ali
|
May 10, 2010 Re: opAddAssign still works | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ali Çehreli | On Mon, 10 May 2010 17:58:37 -0400, Ali Çehreli <acehreli@yahoo.com> wrote: > Steven Schveighoffer wrote: >> I just made a startling discovery: the old operator overload routines still work in 2.045 >> Is this intended? > > I don't know, but I am happy that they still work. I haven't gotten around to changing my code to use the new syntax yet. :) > > I hope the old syntax remains as a deprecated feature and stays supported for the next 15 years or so... :) Well, I've been doing it for dcollections, and I came across this blocker: http://d.puremagic.com/issues/show_bug.cgi?id=4174 -Steve |
May 10, 2010 Re: opAddAssign still works | ||||
---|---|---|---|---|
| ||||
Posted in reply to Steven Schveighoffer | Yeah it still works for compatibility reasons but is deprecated. |
May 11, 2010 Re: opAddAssign still works | ||||
---|---|---|---|---|
| ||||
Posted in reply to Trass3r | On 05/11/2010 01:38 AM, Trass3r wrote:
> Yeah it still works for compatibility reasons but is deprecated.
Not yet, it's not. To compile something that's deprecated, you will need the -d switch.
Right now, both are allowed, but the old one is scheduled for deprecation and presumably later removal. :)
|
May 11, 2010 Re: opAddAssign still works | ||||
---|---|---|---|---|
| ||||
Posted in reply to Pelle | Pelle: > Not yet, it's not. To compile something that's deprecated, you will need the -d switch. That's for user code marked with 'deprecated': http://www.digitalmars.com/d/2.0/attribute.html#deprecated I don't think it is designed to work with compiler/language features too. The D1 compiler has a switch (-v1), that's missing in D2, for deprecated compiler features, maybe something similar will be put back. Bye, bearophile |
May 11, 2010 Re: opAddAssign still works | ||||
---|---|---|---|---|
| ||||
Posted in reply to Trass3r | On Mon, 10 May 2010 19:38:53 -0400, Trass3r <un@known.com> wrote:
> Yeah it still works for compatibility reasons but is deprecated.
Yeah, but should the old method override the new one?
I assumed one nice thing about "backwards compatibility" is you could do something like this:
T opOpAssign(string op)(T other) if (op == "+=")
{
return opAddAssign(other);
}
But this function never gets called. I found out recently that template functions are not allowed in interfaces, which makes it impossible to use the new operator overloads on interfaces.
-Steve
|
May 11, 2010 Re: opAddAssign still works | ||||
---|---|---|---|---|
| ||||
Posted in reply to Steven Schveighoffer | > I found out recently that template
> functions are not allowed in interfaces, which makes it impossible to use
> the new operator overloads on interfaces.
Wow that should find its way into bugzilla.
|
May 11, 2010 Re: opAddAssign still works | ||||
---|---|---|---|---|
| ||||
Posted in reply to Trass3r | On Tue, 11 May 2010 08:52:47 -0400, Trass3r <un@known.com> wrote: >> I found out recently that template >> functions are not allowed in interfaces, which makes it impossible to use >> the new operator overloads on interfaces. > > Wow that should find its way into bugzilla. Already there :) http://d.puremagic.com/issues/show_bug.cgi?id=4174 It was the minimal case I was working on creating where I discovered the old operator functions still work. -Steve |
May 11, 2010 Re: opAddAssign still works | ||||
---|---|---|---|---|
| ||||
Posted in reply to Steven Schveighoffer | Steven Schveighoffer <schveiguy@yahoo.com> wrote: > But this function never gets called. I found out recently that template functions are not allowed in interfaces, which makes it impossible to use the new operator overloads on interfaces. The problem is however, that template functions can't be virtual, and thus can't be stuffed into interfaces. Mayhaps however, specific instantiations could be. Of course, implementing some kind of dynamic vtable, that could be updated at link-time, would make many kinds of magic possible, and might be a solution. No idea how possible this is, though. -- Simen |
Copyright © 1999-2021 by the D Language Foundation