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 #925 from quickfur/issue11761
Browse files Browse the repository at this point in the history
Fix 11761: aa.byKey and aa.byValue are not forward ranges.
  • Loading branch information
9rnsr committed Aug 15, 2014
2 parents 1846223 + af3d9ec commit 38eee4c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/object.di
Expand Up @@ -448,7 +448,7 @@ auto byKey(T : Value[Key], Value, Key)(T aa) pure nothrow @nogc
@property bool empty() { return _aaRangeEmpty(r); }
@property ref Key front() { return *cast(Key*)_aaRangeFrontKey(r); }
void popFront() { _aaRangePopFront(r); }
Result save() { return this; }
@property Result save() { return this; }
}

return Result(_aaRange(cast(void*)aa));
Expand All @@ -469,7 +469,7 @@ auto byValue(T : Value[Key], Value, Key)(T aa) pure nothrow @nogc
@property bool empty() { return _aaRangeEmpty(r); }
@property ref Value front() { return *cast(Value*)_aaRangeFrontValue(r); }
void popFront() { _aaRangePopFront(r); }
Result save() { return this; }
@property Result save() { return this; }
}

return Result(_aaRange(cast(void*)aa));
Expand Down
30 changes: 28 additions & 2 deletions src/object_.d
Expand Up @@ -2044,7 +2044,7 @@ auto byKey(T : Value[Key], Value, Key)(T aa) pure nothrow @nogc
@property bool empty() { return _aaRangeEmpty(r); }
@property ref Key front() { return *cast(Key*)_aaRangeFrontKey(r); }
void popFront() { _aaRangePopFront(r); }
Result save() { return this; }
@property Result save() { return this; }
}

return Result(_aaRange(cast(void*)aa));
Expand All @@ -2065,7 +2065,7 @@ auto byValue(T : Value[Key], Value, Key)(T aa) pure nothrow @nogc
@property bool empty() { return _aaRangeEmpty(r); }
@property ref Value front() { return *cast(Value*)_aaRangeFrontValue(r); }
void popFront() { _aaRangePopFront(r); }
Result save() { return this; }
@property Result save() { return this; }
}

return Result(_aaRange(cast(void*)aa));
Expand Down Expand Up @@ -2302,6 +2302,32 @@ pure nothrow unittest
map.rehash;
}

pure nothrow unittest
{
// bug 11761: test forward range functionality
auto aa = ["a": 1];

void testFwdRange(R, T)(R fwdRange, T testValue)
{
assert(!fwdRange.empty);
assert(fwdRange.front == testValue);
static assert(is(typeof(fwdRange.save) == typeof(fwdRange)));

auto saved = fwdRange.save;
fwdRange.popFront();
assert(fwdRange.empty);

assert(!saved.empty);
assert(saved.front == testValue);
saved.popFront();
assert(saved.empty);
}

testFwdRange(aa.byKey, "a");
testFwdRange(aa.byValue, 1);
//testFwdRange(aa.byPair, tuple("a", 1));
}

deprecated("Please use destroy instead of clear.")
alias destroy clear;

Expand Down

0 comments on commit 38eee4c

Please sign in to comment.