Skip to content

Commit

Permalink
Enhancement 16363
Browse files Browse the repository at this point in the history
Issue 16363 (Cannot construct a random access range using frontTransversal)
https://issues.dlang.org/show_bug.cgi?id=16291

- Added the length property to frontTransversal (only if the length is known)
  • Loading branch information
togrue committed Aug 29, 2016
1 parent e6235e0 commit 7f8158d
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions std/range/package.d
Original file line number Diff line number Diff line change
Expand Up @@ -5752,6 +5752,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 @@ -5859,6 +5869,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 the $(D
n)th element of each of the enclosed ranges. All elements of the
Expand Down

0 comments on commit 7f8158d

Please sign in to comment.