www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Suggestion re opCast

reply Arcane Jill <Arcane_member pathlink.com> writes:
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
next sibling parent "Ivan Senji" <ivan.senji public.srce.hr> writes:
"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 dummy

opCast!!? I should be reading the change log more carefully!
 Like this:

       int opCast(int dummy) { /+ stuff +/ }
       double opCast(double dummy) { /+ stuff +/ }
       char[] opCast(char[] dummy) { /+ stuff +/ }


This would be nice to be able to have more of them.
 You get the idea. When the expression cast(T) is encountered applying to

 object of class A, then A.opCast(T.init) is called. (The implementation of

 function will ignore the dummy value).

 This would allow us to override opCast more than once, for multiple types.

 would be very useful.

 Jill

May 31 2004
prev sibling parent Derek Parnell <derek psych.ward> writes:
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:
 
       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

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 PM
May 31 2004