Skip to content

Commit 95875a7

Browse files
committed
Add an lvalue overload for opCmp
1 parent 9417884 commit 95875a7

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

source/geod24/bitblob.d

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ public struct BitBlob (size_t Bits)
234234
assert(0, "Unexpected char in string passed to BitBlob");
235235
}
236236

237+
/// Support for comparison
237238
public int opCmp (ref const typeof(this) s) const
238239
{
239240
// Reverse because little endian
@@ -242,6 +243,12 @@ public struct BitBlob (size_t Bits)
242243
return b - s.data[idx];
243244
return 0;
244245
}
246+
247+
/// Support for comparison (rvalue overload)
248+
public int opCmp (const typeof(this) s) const
249+
{
250+
return this.opCmp(s);
251+
}
245252
}
246253

247254
pure @safe nothrow @nogc unittest
@@ -359,6 +366,17 @@ unittest
359366
static assert(CTFEability[] == GenesisBlockHash);
360367
}
361368

369+
// Support for rvalue opCmp
370+
unittest
371+
{
372+
alias Hash = BitBlob!(256);
373+
import std.algorithm.sorting : sort;
374+
375+
static Hash getLValue(int) { return Hash.init; }
376+
int[] array = [1, 2];
377+
array.sort!((a, b) => getLValue(a) < getLValue(b));
378+
}
379+
362380
version (unittest)
363381
{
364382
private:

0 commit comments

Comments
 (0)