toImpl deprecated, use opCast instead?

Manu turkeyman at gmail.com
Mon Jun 11 11:19:12 PDT 2012


On 10 June 2012 03:42, Jonathan M Davis <jmdavisProg at gmx.com> wrote:

> 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.
>

That's very problematic for generic programming :/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20120611/98f28f51/attachment.html>


More information about the Digitalmars-d mailing list