summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorEugen Wissner <belka@caraus.de>2018-03-04 09:29:09 +0100
committerEugen Wissner <belka@caraus.de>2018-03-04 09:29:09 +0100
commit81cbb96d4563a7b8ec25b28681979076adb973e4 (patch)
tree537f9b9f4aaa6e7a866c4407df0b26cdaa6fc876 /source
parentdc3b08309740bc080e910109c8a0df4934aafff1 (diff)
parent467335460e911ee449429611c676224cdd593b67 (diff)
downloadtanya-81cbb96d4563a7b8ec25b28681979076adb973e4.tar.gz
Merge remote-tracking branch 'n8sh/isRandomAccessRange-definition'
Diffstat (limited to 'source')
-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