www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Casting syntax

reply "Jeroen van Bemmel" <someone somewhere.com> writes:
Since casting can be considered as invoking a function on an object, 
wouldn't it make sense to allow:

x.cast( int ) where x can be any object or scalar value?
Jun 07 2004
next sibling parent reply Ant <duitoolkit yahoo.ca> writes:
On Tue, 08 Jun 2004 07:58:01 +0200, Jeroen van Bemmel wrote:

 Since casting can be considered as invoking a function on an object, 
 wouldn't it make sense to allow:
 
 x.cast( int ) where x can be any object or scalar value?
obviously, but this was discussed before and rejected. Ant
Jun 07 2004
parent J C Calvarese <jcc7 cox.net> writes:
Ant wrote:
 On Tue, 08 Jun 2004 07:58:01 +0200, Jeroen van Bemmel wrote:
 
 
Since casting can be considered as invoking a function on an object, 
wouldn't it make sense to allow:

x.cast( int ) where x can be any object or scalar value?
obviously, but this was discussed before and rejected. Ant
It has been mentioned before. It looks like a fine suggestion to me, but I don't care enough about it to fight for it. I like the cast(int) x syntax. I think that's good enough. -- Justin (a/k/a jcc7) http://jcc_7.tripod.com/d/
Jun 07 2004
prev sibling next sibling parent Arcane Jill <Arcane_member pathlink.com> writes:
In article <ca3kiu$2r17$1 digitaldaemon.com>, Jeroen van Bemmel says...
Since casting can be considered as invoking a function on an object, 
wouldn't it make sense to allow:

x.cast( int ) where x can be any object or scalar value?
Sure. Another nice one is (one of the many ways that) C++ does it:
        int(x)
That to me is the ultimate in simplicity, and it might even call a constructor in the case of a class. However, I, too, like Walter's approach, so I'm happy to leave things as they are. Jill
Jun 08 2004
prev sibling parent Norbert Nemec <Norbert.Nemec gmx.de> writes:
Jeroen van Bemmel wrote:

 Since casting can be considered as invoking a function on an object,
 wouldn't it make sense to allow:
 
 x.cast( int ) where x can be any object or scalar value?
The problem of this is that it looks like a function call that takes a type as argument. As long as types cannot be handled like that in D in general, I think it is a good idea to leave the cast syntax as it is without trying to make it look similar to something that is fundamentally different.
Jun 09 2004