mirror of
https://github.com/dlang/phobos.git
synced 2025-04-29 06:30:28 +03:00
Make std.string module CTFEable
This commit is contained in:
parent
74b29c478e
commit
edcd51104d
2 changed files with 162 additions and 10 deletions
|
@ -6053,7 +6053,16 @@ int cmp(alias pred = "a < b", R1, R2)(R1 r1, R2 r2) if (isSomeString!R1 && isSom
|
|||
static if (typeof(r1[0]).sizeof == 1)
|
||||
{
|
||||
immutable len = min(r1.length, r2.length);
|
||||
immutable result = std.c.string.memcmp(r1.ptr, r2.ptr, len);
|
||||
immutable result = __ctfe ?
|
||||
{
|
||||
foreach (i; 0 .. len)
|
||||
{
|
||||
if (r1[i] != r2[i])
|
||||
return threeWayInt(r1[i], r2[i]);
|
||||
}
|
||||
return 0;
|
||||
}()
|
||||
: std.c.string.memcmp(r1.ptr, r2.ptr, len);
|
||||
if (result) return result;
|
||||
}
|
||||
else
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue