Andrei reports:
This works with -allinst but not without:
import std.typecons;
interface IDrawable
{
void drawLine(int x1, int y1, int x2, int y2);
}
class ImageDraw // note: it does not inherit IDrawable.
{
void drawLine(int x1, int y1, int x2, int y2) { }
}
/** Draw a rectangle outline. */
void drawRect(IDrawable draw)
{
draw.drawLine( 0, 0, 100, 0);
draw.drawLine(100, 0, 100, 100);
draw.drawLine( 0, 100, 100, 100);
draw.drawLine( 0, 0, 0, 100);
}
void main()
{
auto imageDraw = new ImageDraw();
//drawRect(imageDraw); // error: can't call this, ImageDraw is not an IDrawable.
// perform a structural cast.
IDrawable i = wrap!IDrawable(imageDraw);
drawRect(i); // and now imageDraw can act as an IDrawable.
}
Comment #1 by andrej.mitrovich — 2013-11-06T14:09:49Z