summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathan Sashihara <21227491+n8sh@users.noreply.github.com>2018-02-26 03:21:56 -0500
committerNathan Sashihara <21227491+n8sh@users.noreply.github.com>2018-03-04 03:02:18 -0500
commit467335460e911ee449429611c676224cdd593b67 (patch)
tree8f8185907c4c87cb3af32d07b4937dda25984f15
parent9bf8754711aa3d47fccd66b9735d3fd47d20fae0 (diff)
downloadtanya-467335460e911ee449429611c676224cdd593b67.tar.gz
Decouple isRandomAccessRange from isForwardRange and isBidirectionalRange
-rw-r--r--source/tanya/range/primitive.d20
1 files changed, 11 insertions, 9 deletions
diff --git a/source/tanya/range/primitive.d b/source/tanya/range/primitive.d
index 542ee69..fe47834 100644
--- a/source/tanya/range/primitive.d
+++ b/source/tanya/range/primitive.d
@@ -633,8 +633,8 @@ template isBidirectionalRange(R)
*
* A random-access range is a range that allows random access to its
* elements by index using $(D_INLINECODE [])-operator (defined with
- * $(D_INLINECODE opIndex())). Further a random access range should be a
- * bidirectional range that also has a length or an infinite forward range.
+ * $(D_INLINECODE opIndex())). Further a random access range should
+ * have a length or be infinite.
*
* Params:
* R = The type to be tested.
@@ -642,19 +642,21 @@ template isBidirectionalRange(R)
* Returns: $(D_KEYWORD true) if $(D_PARAM R) is a random-access range,
* $(D_KEYWORD false) otherwise.
*
- * See_Also: $(D_PSYMBOL isBidirectionalRange),
- * $(D_PSYMBOL isForwardRange),
- * $(D_PSYMBOL isInfinite),
+ * See_Also: $(D_PSYMBOL isInfinite),
* $(D_PSYMBOL hasLength).
+ *
+ * Note: This definition differs from `std.range.primitives.isRandomAccessRange`
+ * in the D standard library in that it does not also require $(D_PARAM R) to
+ * be a forward range and a bidirectional range. Those properties may be tested
+ * separately with $(D_PSYMBOL isForwardRange) and
+ * $(D_PSYMBOL isBidirectionalRange).
*/
template isRandomAccessRange(R)
{
static if (is(ReturnType!((R r) => r.opIndex(size_t.init)) U))
{
- private enum bool isBidirectional = isBidirectionalRange!R
- && hasLength!R;
- private enum bool isForward = isInfinite!R && isForwardRange!R;
- enum bool isRandomAccessRange = (isBidirectional || isForward)
+ enum bool isRandomAccessRange = isInputRange!R
+ && (hasLength!R || isInfinite!R)
&& is(U == ReturnType!((R r) => r.front()));
}
else