On Saturday, September 03, 2011 22:13:44 jdrewsen wrote:
> Den 01-09-2011 18:52, Timon Gehr skrev:
> > On 09/01/2011 06:39 PM, jdrewsen wrote:
> >> Den 01-09-2011 05:19, David Nadlinger skrev:
> >>> On 8/25/11 12:05 PM, Jonas Drewsen wrote:
> >>>> Actually would adding opCast!string() and opCast!(ubyte[])() to
> >>>> AsyncResult and Result allow for this?:
> >>>> 
> >>>> string content = Http.get("http://mysite.com/form.cgi";);
> >>>> or
> >>>> ubyte[] content = Http.get("http://mysite.com/form.cgi";);
> >>> 
> >>> It wouldn't, opCast is only taken into account for explicit casts
> >>> (if(something) is considered an explicit cast to bool). For this to
> >>> work, you would have to use alias this, but currently you could only
> >>> provide one of the two conversions.
> >>> 
> >>> David
> >> 
> >> Ok. You can do it in C++. I wonder what this has not been allowed in
> >> D?
> >> 
> >> /Jonas
> > 
> > Because in D there is/should be multiple alias this, which is a better
> > concept to solve the same set of problems.
> 
> Will multiple alias this is currently not supported and AFAIK not
> planned. Furthermore I don't how doing alias this on both string and
> ubyte[] is possible since they share a lot of interface. For example: If
> the class Result has alias this for ubyte[] and for string then what
> does this mean?
> 
> Result res = .....;
> writeln("The length is ", res.length);
> 
> Therefore I still think implicit opCast would be nice. Maybe the opCast
> could have an @implicit attribute or something to make i safer.

TDPL explicitly states that D supports multiple alias this. It just hasn't 
been implemented in dmd yet. It is certainly true though that there may be 
issues with having multiple alias this of types which are too similar, and 
those issues have not necessarily been ironed out yet.

opImplicitCast has been requested on a number of occasions, but there are not 
currently any plans for such a feature. alias this is intended to fulfill that 
role, and I don't see how opImplicitCast would really be any different from 
alias this, since you can give a function to alias this already (and then the 
type implicitly converts to the function's return type).

- Jonathan M Davis

Reply via email to