Overloading opCast with multiple types
Stewart Gordon
smjg_1998 at yahoo.com
Sun Oct 1 11:29:31 PDT 2006
Reiner Pope wrote:
> As we all know, opCast can only have one overload per class, because D
> doesn't support overloading by return type. That is a really silly
> limitation, in my opinion. Anyway, I have a solution here: give it a
> parameter, which is the type (we pass this parameter in the form of a
> template). Here's the magic:
>
> class Test
> {
> int x;
> Foo myCast(TFoo : Foo)() { static assert(is(TFoo == Foo), "No cast
> of the required type exists"); return new Foo(x); }
<snip>
Something to this effect has been proposed before.
However, the idea of having to put a static assert in each would make it
somewhat more cumbersome than it should be. Moreover, a problem with
using templates is deciding how the vtbl would work.
There have been a number of proposals for ways to do multiple casts.
http://www.prowiki.org/wiki4d/wiki.cgi?FeatureRequestList
My proposal:
http://tinyurl.com/p2pn4
Stewart.
--
-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GCS/M d- s:-@ C++@ a->--- UB@ P+ L E@ W++@ N+++ o K-@ w++@ O? M V? PS-
PE- Y? PGP- t- 5? X? R b DI? D G e++++ h-- r-- !y
------END GEEK CODE BLOCK------
My e-mail is valid but not my primary mailbox. Please keep replies on
the 'group where everyone may benefit.
More information about the Digitalmars-d
mailing list