Duck typing for structs

Ash Logan ash.logior at gmail.com
Thu Oct 21 08:36:29 PDT 2010


Hello all,

I was experimenting with Kenji Hara's interfaces.d, and I thought it
would be interesting to be able to adapt not just objects but struct
values to an interface. So I came up with a hacky solution, adapter.d,
and put it on Google Docs at

http://goo.gl/Y7Oa

in case anyone is interested. The unit tests have examples of usage with
structs and classes (including classes with methods added by mixin
templates, and structs with aliases to methods); there are several weird
bugs relating to overloaded methods, but more things work than I
expected to when I started. I don't know if this could turn into
something useful, or if it's just a curiosity, but I wanted to see what
the D community thought of it.

-- Ash


More information about the Digitalmars-d mailing list