digitalmars.D - Suggestion re opCast
- Arcane Jill (8/11) May 30 2004 You get the idea. When the expression cast(T) is encountered applying to...
- Ivan Senji (8/19) May 31 2004 argument.
- Derek Parnell (7/22) May 31 2004 Agreed. When a coder enters 'cast(whatever)A', the author of the class t...
Dunno what you think of this, but I suggest that opCast take a dummy argument. Like this:int opCast(int dummy) { /+ stuff +/ } double opCast(double dummy) { /+ stuff +/ } char[] opCast(char[] dummy) { /+ stuff +/ }You get the idea. When the expression cast(T) is encountered applying to some object of class A, then A.opCast(T.init) is called. (The implementation of the function will ignore the dummy value). This would allow us to override opCast more than once, for multiple types. This would be very useful. Jill
May 30 2004
"Arcane Jill" <Arcane_member pathlink.com> wrote in message news:c9dm4r$11mt$1 digitaldaemon.com...Dunno what you think of this, but I suggest that opCast take a dummyargument. opCast!!? I should be reading the change log more carefully!Like this:This would be nice to be able to have more of them.int opCast(int dummy) { /+ stuff +/ } double opCast(double dummy) { /+ stuff +/ } char[] opCast(char[] dummy) { /+ stuff +/ }You get the idea. When the expression cast(T) is encountered applying tosomeobject of class A, then A.opCast(T.init) is called. (The implementation ofthefunction will ignore the dummy value). This would allow us to override opCast more than once, for multiple types.Thiswould be very useful. Jill
May 31 2004
On Sun, 30 May 2004 22:10:35 +0000 (UTC), Arcane Jill wrote:Dunno what you think of this, but I suggest that opCast take a dummy argument. Like this:Agreed. When a coder enters 'cast(whatever)A', the author of the class that A belongs to needs to know how to convert an instance of the class into the requested type. -- Derek 1/Jun/04 3:37:27 PMint opCast(int dummy) { /+ stuff +/ } double opCast(double dummy) { /+ stuff +/ } char[] opCast(char[] dummy) { /+ stuff +/ }You get the idea. When the expression cast(T) is encountered applying to some object of class A, then A.opCast(T.init) is called. (The implementation of the function will ignore the dummy value). This would allow us to override opCast more than once, for multiple types. This would be very useful. Jill
May 31 2004