Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Commit

Permalink
Merge pull request #1079 from quickfur/issue9119_const
Browse files Browse the repository at this point in the history
byKeyValue should also work with const loop variables.
  • Loading branch information
AndrejMitrovic committed Jan 4, 2015
2 parents b3a8032 + a1f9857 commit 9ec46a6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/object.di
Expand Up @@ -542,8 +542,8 @@ auto byKeyValue(T : Value[Key], Value, Key)(T aa) pure nothrow @nogc @property
private Key* keyp;
private Value* valp;

@property ref Key key() { return *keyp; }
@property ref Value value() { return *valp; }
@property ref inout(Key) key() inout { return *keyp; }
@property ref inout(Value) value() inout { return *valp; }
}
return Pair(cast(Key*)_aaRangeFrontKey(r),
cast(Value*)_aaRangeFrontValue(r));
Expand Down
15 changes: 13 additions & 2 deletions src/object_.d
Expand Up @@ -2142,8 +2142,8 @@ auto byKeyValue(T : Value[Key], Value, Key)(T aa) pure nothrow @nogc @property
private Key* keyp;
private Value* valp;

@property ref Key key() { return *keyp; }
@property ref Value value() { return *valp; }
@property ref inout(Key) key() inout { return *keyp; }
@property ref inout(Value) value() inout { return *valp; }
}
return Pair(cast(Key*)_aaRangeFrontKey(r),
cast(Value*)_aaRangeFrontValue(r));
Expand Down Expand Up @@ -2419,6 +2419,17 @@ unittest
assert(count == aa.length);
}

unittest
{
// Verify iteration with const.
auto aa = [1:2, 3:4];
foreach (const t; aa.byKeyValue)
{
auto k = t.key;
auto v = t.value;
}
}

// Explicitly undocumented. It will be removed in March 2015.
deprecated("Please use destroy instead of clear.")
alias destroy clear;
Expand Down

0 comments on commit 9ec46a6

Please sign in to comment.