Interfaces with structs...?

Era Scarecrow rtcvb32 at yahoo.com
Thu Jul 5 11:37:59 PDT 2012


On Thursday, 5 July 2012 at 18:30:51 UTC, Jonathan M Davis wrote:
> Aside from the problem that it looks like inheritance when it's 
> not, declaring an interface for a struct would actually be too 
> restrictive in many cases.

<snip>

> If it were defined with an interface, how would you deal with 
> the fact that none of the types are fixed? Templatize the 
> interface? That might work, but the more complicated the 
> requirements for the template constaint, the harder that will 
> be, and I'm not sure that it can even always work to do that. 
> What we have may take some getting used to, but it works really 
> well.

  Mmm.. maybe 'interface' is the wrong word. More like 'qualifies 
to use the following template(s)'... I was thinking it more like 
an early static check ensuring the struct hits certain 
requirements, outside of the early checks it is completely 
ignored and structs work as normal. (Like the unittest example I 
gave)

  Having it use an actual interface wouldn't work well due to how 
diverse the various templates functions that call on the structs 
work.


More information about the Digitalmars-d-learn mailing list