diff options
| author | Eugen Wissner <belka@caraus.de> | 2019-01-09 18:17:41 +0100 |
|---|---|---|
| committer | Eugen Wissner <belka@caraus.de> | 2019-01-09 18:17:41 +0100 |
| commit | 50aaa170fbd27f549eec27d782e6e51474b1ba06 (patch) | |
| tree | 42dedd872bc654aba4fbb9da0fb2511cdbb24d04 | |
| parent | 03e21d43687483422dad67824a927264ec3c4ee1 (diff) | |
| parent | ff7d20f167ff463b1c40ced831f904e9e14bd062 (diff) | |
| download | tanya-50aaa170fbd27f549eec27d782e6e51474b1ba06.tar.gz | |
Merge remote-tracking branch 'n8sh/retro-slicing'
| -rw-r--r-- | source/tanya/algorithm/iteration.d | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/source/tanya/algorithm/iteration.d b/source/tanya/algorithm/iteration.d index bfd1f13..8281ae1 100644 --- a/source/tanya/algorithm/iteration.d +++ b/source/tanya/algorithm/iteration.d @@ -514,6 +514,22 @@ private struct Retro(Range) } } + static if (hasLength!Range && hasSlicing!Range) + { + alias opDollar = length; + + auto opSlice(size_t i, size_t j) + in + { + assert(i <= j); + assert(j <= length); + } + do + { + return typeof(this)(this.source[$-j .. $-i]); + } + } + static if (hasAssignableElements!Range) { @property void front(ref ElementType!Range value) @@ -609,6 +625,10 @@ if (isBidirectionalRange!Range) actual.popBack(); assert(actual.back == 2); assert(actual[1] == 2); + + // Check slicing. + auto slice = retro(given[])[1 .. $]; + assert(slice.length == 2 && slice.front == 2 && slice.back == 1); } // Elements can be assigned |
