On Thursday, 30 October 2014 at 00:10:47 UTC, H. S. Teoh via Digitalmars-d wrote:
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.

It's already covered by the DIP. Simply, it's one of the requirements of an associative range: "byKey and byValue must be align to the same Pair when iterating." While the compiler can't enforce this, there are many things about ranges which the compiler is unable to check, so we merely expect the implementation to follow the rules.

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

Reply via email to