Skip to content

Commit

Permalink
Merge pull request #4754 from togrue/issue_16363
Browse files Browse the repository at this point in the history
Fix issue 16363 - Cannot construct a random access range using frontTransversal
  • Loading branch information
wilzbach committed Aug 29, 2016
2 parents 1d48fb9 + b450113 commit 6394458
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions std/range/package.d
Expand Up @@ -5902,6 +5902,16 @@ struct FrontTransversal(Ror,
_input[n].front = val;
}
}
/// Ditto
static if (hasLength!RangeOfRanges)
{
@property size_t length()
{
return _input.length;
}

alias opDollar = length;
}

/**
Slicing if offered if $(D RangeOfRanges) supports slicing and all the
Expand Down Expand Up @@ -6009,6 +6019,18 @@ FrontTransversal!(RangeOfRanges, opt) frontTransversal(
}
}

// Issue 16363
@safe unittest
{
import std.algorithm.comparison : equal;

int[][] darr = [[0, 1], [4, 5]];
auto ft = frontTransversal!(TransverseOptions.assumeNotJagged)(darr);

assert(equal(ft, [0, 4]));
static assert(isRandomAccessRange!(typeof(ft)));
}

/**
Given a range of ranges, iterate transversally through the
`n`th element of each of the enclosed ranges.
Expand Down

0 comments on commit 6394458

Please sign in to comment.