toImpl deprecated, use opCast instead?

Jonathan M Davis jmdavisProg at gmx.com
Sat Jun 9 17:42:01 PDT 2012


On Sunday, June 10, 2012 02:26:36 timotheecour wrote:
> What is the recommended approach when we have no control over
> classes A or B (cf from 3rd party) to convert A to B?
> It seems UFCS doesn't work in that case.
> Could you please provide an example code?
> Thanks!

If you want to convert between two types and you don't control the definitions 
of either, and neither of them have any functions which will convert from one 
to the (including constructors, opCast, etc.), then you're just going to have 
to write a function to do it. It's not gonig to work with std.conv.to or 
casting, but you can write such a function just like you can write any other 
function.

A convertBToA(B b) {...}

I don't think tha there's anything else that you _can_ do.

- Jonathan M Davis


More information about the Digitalmars-d mailing list