DIP67: Associative Ranges

Brad Anderson via Digitalmars-d digitalmars-d at puremagic.com
Tue Oct 28 19:11:16 PDT 2014


On Tuesday, 28 October 2014 at 22:44:32 UTC, Freddy wrote:
> http://wiki.dlang.org/DIP67
> Abstraction over the build-in associative array(one type of 
> range
> for containers and another type for dynamic generators).
> Plese criticize.

It's kind of a weird proposal to be honest. Ranges primitives are
normally things like popFront(), front, and empty. The primitives
here are methods that return other ranges.

I'd think an associative range would be one that had something
like frontKey and frontValue. Alternatively it could be anything
with a front which is a 2-element tuple  (a lot like how C++'s
associative iterators have a std::pair<KeyTy, ValueTy>
value_type) but tuples aren't in druntime so that'd be a problem.

I've always found byKey and byValue odd because you rarely want
to iterate through an associative array without having both the
key and the value on hand. Doing byKey requires you to do a
lookup to get the corresponding value which just takes up cycles
unnecessarily. It also makes multimaps, if we ever support them,
a bit problematic (that is, associative arrays which support
storing a key more than once).


More information about the Digitalmars-d mailing list