diff options
| author | Eugen Wissner <belka@caraus.de> | 2018-09-17 19:17:39 +0200 |
|---|---|---|
| committer | Eugen Wissner <belka@caraus.de> | 2018-09-17 19:17:39 +0200 |
| commit | b0dc7b59e570849e55894ae99a9d162247ccc329 (patch) | |
| tree | 516c398b5e3888161a1a3a7c57baf69dd3558933 | |
| parent | eb796e0ddf49312e01fcf2cab42b93d40c1c61eb (diff) | |
| download | tanya-b0dc7b59e570849e55894ae99a9d162247ccc329.tar.gz | |
Add predicate support for algorithm.comparison.equal
| -rw-r--r-- | source/tanya/algorithm/comparison.d | 17 | ||||
| -rw-r--r-- | source/tanya/container/array.d | 4 |
2 files changed, 12 insertions, 9 deletions
diff --git a/source/tanya/algorithm/comparison.d b/source/tanya/algorithm/comparison.d index bf2ac34..88f6860 100644 --- a/source/tanya/algorithm/comparison.d +++ b/source/tanya/algorithm/comparison.d @@ -278,16 +278,19 @@ if (isForwardRange!Range && isOrderingComparable!(ElementType!Range)) * If the ranges have different lengths, they aren't equal. * * Params: - * R1 = First range type. - * R2 = Second range type. - * r1 = First range. - * r2 = Second range. + * pred = Predicate used to compare individual element pairs. + * R1 = First range type. + * R2 = Second range type. + * r1 = First range. + * r2 = Second range. * * Returns: $(D_KEYWORD true) if both ranges are equal, $(D_KEYWORD false) * otherwise. */ -bool equal(R1, R2)(R1 r1, R2 r2) -if (allSatisfy!(isInputRange, R1, R2) && is(typeof(r1.front == r2.front))) +bool equal(alias pred = (auto ref a, auto ref b) => a == b, R1, R2) + (R1 r1, R2 r2) +if (allSatisfy!(isInputRange, R1, R2) + && is(typeof(pred(r1.front, r2.front)) == bool)) { static if (isDynamicArray!R1 && is(R1 == R2) @@ -306,7 +309,7 @@ if (allSatisfy!(isInputRange, R1, R2) && is(typeof(r1.front == r2.front))) } for (; !r1.empty && !r2.empty; r1.popFront(), r2.popFront()) { - if (r1.front != r2.front) + if (!pred(r1.front, r2.front)) { return false; } diff --git a/source/tanya/container/array.d b/source/tanya/container/array.d index 59cc3fb..78e4dd5 100644 --- a/source/tanya/container/array.d +++ b/source/tanya/container/array.d @@ -1554,14 +1554,14 @@ struct Array(T) { struct MutableEqualsStruct { - int opEquals(typeof(this) that) @nogc nothrow pure @safe + bool opEquals(typeof(this) that) @nogc nothrow pure @safe { return true; } } struct ConstEqualsStruct { - int opEquals(const typeof(this) that) const @nogc nothrow pure @safe + bool opEquals(const typeof(this) that) const @nogc nothrow pure @safe { return true; } |
