Skip to content

Commit

Permalink
Merge pull request #5668 from quickfur/issue17711
Browse files Browse the repository at this point in the history
Fix issue 17711: std.array.byPair ought to work with const AA's.
merged-on-behalf-of: Petar Kirov <ZombineDev@users.noreply.github.com>
  • Loading branch information
dlang-bot committed Aug 2, 2017
2 parents 08e3703 + 0c0aed8 commit e4e858b
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion std/array.d
Expand Up @@ -428,7 +428,7 @@ Params: aa = The associative array to iterate over.
Returns: A $(REF_ALTTEXT forward range, isForwardRange, std,_range,primitives)
of Tuple's of key and value pairs from the given associative array.
*/
auto byPair(Key, Value)(Value[Key] aa)
auto byPair(AA : Value[Key], Value, Key)(AA aa)
{
import std.algorithm.iteration : map;
import std.typecons : tuple;
Expand Down Expand Up @@ -482,6 +482,26 @@ auto byPair(Key, Value)(Value[Key] aa)
assert(savedPairs.front == tuple("a", 2));
}

// Issue 17711
@system unittest
{
const(int[string]) aa = [ "abc": 123 ];

// Ensure that byKeyValue is usable with a const AA.
auto kv = aa.byKeyValue;
assert(!kv.empty);
assert(kv.front.key == "abc" && kv.front.value == 123);
kv.popFront();
assert(kv.empty);

// Ensure byPair is instantiable with const AA.
auto r = aa.byPair;
static assert(isInputRange!(typeof(r)));
assert(!r.empty && r.front[0] == "abc" && r.front[1] == 123);
r.popFront();
assert(r.empty);
}

private template blockAttribute(T)
{
import core.memory;
Expand Down

0 comments on commit e4e858b

Please sign in to comment.