mirror of
https://github.com/dlang/phobos.git
synced 2025-05-01 15:40:36 +03:00
Added auto-decoding special case to std.algorithm.comparison.equal
This commit is contained in:
parent
b284e965fe
commit
cb073a2cc9
1 changed files with 33 additions and 0 deletions
|
@ -736,6 +736,27 @@ template equal(alias pred = "a == b")
|
|||
{
|
||||
return r1 == r2;
|
||||
}
|
||||
// if one of the arguments is a string and the other isn't, then auto-decoding
|
||||
// can be avoided if they have the same ElementEncodingType
|
||||
else static if (is(typeof(pred) == string) && pred == "a == b" &&
|
||||
isAutodecodableString!Range1 != isAutodecodableString!Range2 &&
|
||||
is(ElementEncodingType!Range1 == ElementEncodingType!Range2))
|
||||
{
|
||||
import std.utf : byCodeUnit;
|
||||
|
||||
static if (isAutodecodableString!Range1)
|
||||
{
|
||||
auto codeUnits = r1.byCodeUnit;
|
||||
alias other = r2;
|
||||
}
|
||||
else
|
||||
{
|
||||
auto codeUnits = r2.byCodeUnit;
|
||||
alias other = r1;
|
||||
}
|
||||
|
||||
return equal(codeUnits, other);
|
||||
}
|
||||
//Try a fast implementation when the ranges have comparable lengths
|
||||
else static if (hasLength!Range1 && hasLength!Range2 && is(typeof(r1.length == r2.length)))
|
||||
{
|
||||
|
@ -863,6 +884,18 @@ range of range (of range...) comparisons.
|
|||
assert(!equal(a, ifr));
|
||||
}
|
||||
|
||||
@safe pure unittest
|
||||
{
|
||||
import std.utf : byChar, byWchar, byDchar;
|
||||
|
||||
assert(equal("æøå".byChar, "æøå"));
|
||||
assert(equal("æøå", "æøå".byChar));
|
||||
assert(equal("æøå".byWchar, "æøå"w));
|
||||
assert(equal("æøå"w, "æøå".byWchar));
|
||||
assert(equal("æøå".byDchar, "æøå"d));
|
||||
assert(equal("æøå"d, "æøå".byDchar));
|
||||
}
|
||||
|
||||
// MaxType
|
||||
private template MaxType(T...)
|
||||
if (T.length >= 1)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue