DIP67: Associative Ranges
H. S. Teoh via Digitalmars-d
digitalmars-d at puremagic.com
Wed Oct 29 17:08:44 PDT 2014
On Wed, Oct 29, 2014 at 11:33:53PM +0000, Freddy via Digitalmars-d wrote:
> On Wednesday, 29 October 2014 at 19:55:14 UTC, H. S. Teoh via
> Digitalmars-d wrote:
[...]
> >And how would it be implemented in a way that is stable across AA
> >implementations?
> >
> >
> >--T
> in std.range
> ----
> auto byKeyPair(R)(R r) if(isAssociativeRange!R){
> return zip(r.byKey,r.byValue);
> }
> ----
This is not stable across AA implementations. There is no guarantee
that byKey and byValue will return elements in the same order. The
current implementation does, but it's a shaky assumption.
Besides, it wastefully keeps two iterators over the AA, whereas a proper
native implementation would only need a single one.
In any case, this is a backwards approach. What we *should* have started
with, is an iteration over key/value pairs, with byKey and byValue
implemented on top of that, rather than the other way round.
If it weren't for the std.typecons.Tuple issue, we'd already have a
proper AA byPair by now. But perhaps there is a way to work around this,
if the AA interface can export a "raw" iteration function that can be
wrapped in Phobos to produce a range of key/value Tuples... It wouldn't
be the prettiest solution, but might be the best we can do right now
since we can't import Phobos from druntime.
T
--
Windows 95 was a joke, and Windows 98 was the punchline.
More information about the Digitalmars-d
mailing list