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.

/Jonas

Reply via email to