in operator generalization
Regan Heath
regan at netwin.co.nz
Sat Mar 18 02:45:38 PST 2006
On Fri, 17 Mar 2006 17:50:02 -0500, Les Baker
<les_baker at REMOVEbellsouthREMOVE.net> wrote:
> Looking through old NG posts I found this one by Ben Hinkle last year
> about extending the "in" operator to support static/dynamic arrays.
>
> http://www.digitalmars.com/d/archives/digitalmars/D/25164
>
> Was this ever totally dismissed? It just seemed to fall off the radar.
> I'm liking the concept though; I don't know how many times I've
> written loops in quickie utility programs just to hunt for a item and
> return it. I would also additionally suggest (if it hasn't already
> been) that "in" be overloadable so that if D supports other data
> structures in the standard library that they can use that syntax as well.
>
> The only disadvantage I can think of is that when a developer sees "in",
> he/she can't assume it's a constant time operation anymore. I think the
> increase in utility outweights that though.
>
> Thoughts?
I think it might be better to keep this in library code, i.e. it could be
achieved with a utility functions or template. i.e. a template that does a
binary search of a (presumed sorted) object which can be indexed with [],
etc. It could then be used on dynamic/static arrays and other container
style objects. This sort of thing is what I'd expect to see in the
proposed DTL library.
Regan
More information about the Digitalmars-d
mailing list