Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 30 additions & 29 deletions std/algorithm/comparison.d
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ range.
*/
uint among(alias pred = (a, b) => a == b, Value, Values...)
(Value value, Values values)
if (Values.length != 0)
if (Values.length != 0)
{
foreach (uint i, ref v; values)
{
Expand All @@ -96,7 +96,7 @@ uint among(alias pred = (a, b) => a == b, Value, Values...)

/// Ditto
template among(values...)
if (isExpressionTuple!values)
if (isExpressionTuple!values)
{
uint among(Value)(Value value)
if (!is(CommonType!(Value, values) == void))
Expand Down Expand Up @@ -617,7 +617,8 @@ if (isInputRange!R1 && isInputRange!R2 && !(isSomeString!R1 && isSomeString!R2))
}

/// ditto
int cmp(alias pred = "a < b", R1, R2)(R1 r1, R2 r2) if (isSomeString!R1 && isSomeString!R2)
int cmp(alias pred = "a < b", R1, R2)(R1 r1, R2 r2)
if (isSomeString!R1 && isSomeString!R2)
{
import core.stdc.string : memcmp;
import std.utf : decode;
Expand Down Expand Up @@ -958,7 +959,7 @@ range of range (of range...) comparisons.

// MaxType
private template MaxType(T...)
if (T.length >= 1)
if (T.length >= 1)
{
static if (T.length == 1)
{
Expand Down Expand Up @@ -1200,7 +1201,7 @@ Does not allocate GC memory.
*/
size_t levenshteinDistance(alias equals = (a,b) => a == b, Range1, Range2)
(Range1 s, Range2 t)
if (isForwardRange!(Range1) && isForwardRange!(Range2))
if (isForwardRange!(Range1) && isForwardRange!(Range2))
{
alias eq = binaryFun!(equals);

Expand Down Expand Up @@ -1271,7 +1272,7 @@ size_t levenshteinDistance(alias equals = (a,b) => a == b, Range1, Range2)
/// ditto
size_t levenshteinDistance(alias equals = (a,b) => a == b, Range1, Range2)
(auto ref Range1 s, auto ref Range2 t)
if (isConvertibleToString!Range1 || isConvertibleToString!Range2)
if (isConvertibleToString!Range1 || isConvertibleToString!Range2)
{
import std.meta : staticMap;
alias Types = staticMap!(convertToString, Range1, Range2);
Expand Down Expand Up @@ -1312,7 +1313,7 @@ Allocates GC memory for the returned EditOp[] array.
Tuple!(size_t, EditOp[])
levenshteinDistanceAndPath(alias equals = (a,b) => a == b, Range1, Range2)
(Range1 s, Range2 t)
if (isForwardRange!(Range1) && isForwardRange!(Range2))
if (isForwardRange!(Range1) && isForwardRange!(Range2))
{
Levenshtein!(Range1, binaryFun!(equals)) lev;
auto d = lev.distanceWithPath(s, t);
Expand Down Expand Up @@ -1344,7 +1345,7 @@ levenshteinDistanceAndPath(alias equals = (a,b) => a == b, Range1, Range2)
Tuple!(size_t, EditOp[])
levenshteinDistanceAndPath(alias equals = (a,b) => a == b, Range1, Range2)
(auto ref Range1 s, auto ref Range2 t)
if (isConvertibleToString!Range1 || isConvertibleToString!Range2)
if (isConvertibleToString!Range1 || isConvertibleToString!Range2)
{
import std.meta : staticMap;
alias Types = staticMap!(convertToString, Range1, Range2);
Expand Down Expand Up @@ -1375,7 +1376,7 @@ See_Also:
$(REF maxElement, std,algorithm,searching)
*/
MaxType!T max(T...)(T args)
if (T.length >= 2)
if (T.length >= 2)
{
//Get "a"
static if (T.length <= 2)
Expand Down Expand Up @@ -1448,7 +1449,7 @@ MaxType!T max(T...)(T args)

// MinType
private template MinType(T...)
if (T.length >= 1)
if (T.length >= 1)
{
static if (T.length == 1)
{
Expand Down Expand Up @@ -1489,7 +1490,7 @@ See_Also:
$(REF minElement, std,algorithm,searching)
*/
MinType!T min(T...)(T args)
if (T.length >= 2)
if (T.length >= 2)
{
//Get "a"
static if (T.length <= 2)
Expand Down Expand Up @@ -1560,7 +1561,7 @@ See_Also:
*/
Tuple!(Range1, Range2)
mismatch(alias pred = "a == b", Range1, Range2)(Range1 r1, Range2 r2)
if (isInputRange!(Range1) && isInputRange!(Range2))
if (isInputRange!(Range1) && isInputRange!(Range2))
{
for (; !r1.empty && !r2.empty; r1.popFront(), r2.popFront())
{
Expand Down Expand Up @@ -1745,10 +1746,10 @@ Returns:
$(D true) if both ranges have the same length, $(D false) otherwise.
*/
bool isSameLength(Range1, Range2)(Range1 r1, Range2 r2)
if (isInputRange!Range1 &&
isInputRange!Range2 &&
!isInfinite!Range1 &&
!isInfinite!Range2)
if (isInputRange!Range1 &&
isInputRange!Range2 &&
!isInfinite!Range1 &&
!isInfinite!Range2)
{
static if (hasLength!(Range1) && hasLength!(Range2))
{
Expand Down Expand Up @@ -1889,11 +1890,11 @@ Returns:

bool isPermutation(AllocateGC allocate_gc, Range1, Range2)
(Range1 r1, Range2 r2)
if (allocate_gc == Yes.allocateGC &&
isForwardRange!Range1 &&
isForwardRange!Range2 &&
!isInfinite!Range1 &&
!isInfinite!Range2)
if (allocate_gc == Yes.allocateGC &&
isForwardRange!Range1 &&
isForwardRange!Range2 &&
!isInfinite!Range1 &&
!isInfinite!Range2)
{
alias E1 = Unqual!(ElementType!Range1);
alias E2 = Unqual!(ElementType!Range2);
Expand Down Expand Up @@ -1937,11 +1938,11 @@ bool isPermutation(AllocateGC allocate_gc, Range1, Range2)
/// ditto
bool isPermutation(alias pred = "a == b", Range1, Range2)
(Range1 r1, Range2 r2)
if (is(typeof(binaryFun!(pred))) &&
isForwardRange!Range1 &&
isForwardRange!Range2 &&
!isInfinite!Range1 &&
!isInfinite!Range2)
if (is(typeof(binaryFun!(pred))) &&
isForwardRange!Range1 &&
isForwardRange!Range2 &&
!isInfinite!Range1 &&
!isInfinite!Range2)
{
import std.algorithm.searching : count;

Expand Down Expand Up @@ -2093,9 +2094,9 @@ Returns:
The _first argument that passes the test `pred`.
*/
CommonType!(T, Ts) either(alias pred = a => a, T, Ts...)(T first, lazy Ts alternatives)
if (alternatives.length >= 1 &&
!is(CommonType!(T, Ts) == void) &&
allSatisfy!(ifTestable, T, Ts))
if (alternatives.length >= 1 &&
!is(CommonType!(T, Ts) == void) &&
allSatisfy!(ifTestable, T, Ts))
{
alias predFun = unaryFun!pred;

Expand Down
36 changes: 22 additions & 14 deletions std/algorithm/iteration.d
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ import std.functional; // : unaryFun, binaryFun;
import std.range.primitives;
import std.traits;

private template aggregate(fun...) if (fun.length >= 1)
private template aggregate(fun...)
if (fun.length >= 1)
{
/* --Intentionally not ddoc--
* Aggregates elements in each subrange of the given range of ranges using
Expand Down Expand Up @@ -453,7 +454,8 @@ Returns:
See_Also:
$(HTTP en.wikipedia.org/wiki/Map_(higher-order_function), Map (higher-order function))
*/
template map(fun...) if (fun.length >= 1)
template map(fun...)
if (fun.length >= 1)
{
auto map(Range)(Range r) if (isInputRange!(Unqual!Range))
{
Expand Down Expand Up @@ -1084,7 +1086,8 @@ Returns:
See_Also:
$(HTTP en.wikipedia.org/wiki/Filter_(higher-order_function), Filter (higher-order function))
*/
template filter(alias predicate) if (is(typeof(unaryFun!predicate)))
template filter(alias predicate)
if (is(typeof(unaryFun!predicate)))
{
auto filter(Range)(Range range) if (isInputRange!(Unqual!Range))
{
Expand Down Expand Up @@ -1394,7 +1397,8 @@ Group!(pred, Range) group(alias pred = "a == b", Range)(Range r)
}

/// ditto
struct Group(alias pred, R) if (isInputRange!R)
struct Group(alias pred, R)
if (isInputRange!R)
{
import std.typecons : Rebindable, tuple, Tuple;

Expand Down Expand Up @@ -1542,7 +1546,7 @@ struct Group(alias pred, R) if (isInputRange!R)

// Used by implementation of chunkBy for non-forward input ranges.
private struct ChunkByChunkImpl(alias pred, Range)
if (isInputRange!Range && !isForwardRange!Range)
if (isInputRange!Range && !isForwardRange!Range)
{
alias fun = binaryFun!pred;

Expand Down Expand Up @@ -1581,7 +1585,7 @@ private template ChunkByImplIsUnary(alias pred, Range)

// Implementation of chunkBy for non-forward input ranges.
private struct ChunkByImpl(alias pred, Range)
if (isInputRange!Range && !isForwardRange!Range)
if (isInputRange!Range && !isForwardRange!Range)
{
enum bool isUnary = ChunkByImplIsUnary!(pred, Range);

Expand Down Expand Up @@ -1645,7 +1649,7 @@ private struct ChunkByImpl(alias pred, Range)

// Single-pass implementation of chunkBy for forward ranges.
private struct ChunkByImpl(alias pred, Range)
if (isForwardRange!Range)
if (isForwardRange!Range)
{
import std.typecons : RefCounted;

Expand Down Expand Up @@ -1861,7 +1865,7 @@ private struct ChunkByImpl(alias pred, Range)
* element.
*/
auto chunkBy(alias pred, Range)(Range r)
if (isInputRange!Range)
if (isInputRange!Range)
{
return ChunkByImpl!(pred, Range)(r);
}
Expand Down Expand Up @@ -2699,7 +2703,8 @@ See_Also:
$(LREF sum) is similar to $(D reduce!((a, b) => a + b)) that offers
pairwise summing of floating point numbers.
+/
template reduce(fun...) if (fun.length >= 1)
template reduce(fun...)
if (fun.length >= 1)
{
import std.meta : staticMap;

Expand Down Expand Up @@ -3068,7 +3073,8 @@ The number of seeds must be correspondingly increased.
//http://forum.dlang.org/post/oghtttkopzjshsuflelk@forum.dlang.org
//Seed is tuple of const.
static auto minmaxElement(alias F = min, alias G = max, R)(in R range)
@safe pure nothrow if (isInputRange!R)
@safe pure nothrow
if (isInputRange!R)
{
return reduce!(F, G)(tuple(ElementType!R.max,
ElementType!R.min), range);
Expand Down Expand Up @@ -3149,7 +3155,8 @@ See_Also:
This is functionally equivalent to $(LREF reduce) with the argument order reversed,
and without the need to use $(LREF tuple) for multiple seeds.
+/
template fold(fun...) if (fun.length >= 1)
template fold(fun...)
if (fun.length >= 1)
{
auto fold(R, S...)(R r, S seed)
{
Expand Down Expand Up @@ -3522,7 +3529,8 @@ The number of seeds must be correspondingly increased.

//Seed is tuple of const.
static auto minmaxElement(alias F = min, alias G = max, R)(in R range)
@safe pure nothrow if (isInputRange!R)
@safe pure nothrow
if (isInputRange!R)
{
return range.cumulativeFold!(F, G)(tuple(ElementType!R.max, ElementType!R.min));
}
Expand Down Expand Up @@ -5121,14 +5129,14 @@ See_Also:
$(REF nextPermutation, std,algorithm,sorting).
*/
Permutations!Range permutations(Range)(Range r)
if (isRandomAccessRange!Range && hasLength!Range)
if (isRandomAccessRange!Range && hasLength!Range)
{
return typeof(return)(r);
}

/// ditto
struct Permutations(Range)
if (isRandomAccessRange!Range && hasLength!Range)
if (isRandomAccessRange!Range && hasLength!Range)
{
private size_t[] _indices, _state;
private Range _r;
Expand Down
Loading