static interface

dsimcha dsimcha at yahoo.com
Tue Nov 17 06:16:43 PST 2009


== Quote from Leandro Lucarella (llucax at gmail.com)'s article
> Lars T. Kyllingstad, el 17 de noviembre a las 09:54 me escribiste:
> > >In some ways the current code is better, because it actually checks if
> > >a construct works or not, rather than requiring a specific function
> > >signature.  Whether the code will work is really the minimal
> > >restriction you can place on the interface.  A specific may be too
> > >tight.  For instance, above you don't really care if empty returns
> > >bool or not.  Just if you can test it in an "if".
> >
> > Another, related way in which the current code is better is that it
> > doesn't care whether empty, front, and popFront are functions or
> > variables.  As we know, the standard trick for infinite ranges is to
> > declare empty as an enum, not a function.
> Is not that hard to write:
> bool empty() { return false; }
> instead of
> enum bool empty = false;

Yes, but there's a reason to use enum:  This convention enables compile time
introspection as to whether the ranges are infinite.  It's also more efficient
when inlining is disabled.



More information about the Digitalmars-d mailing list