File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed
Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Original file line number Diff line number Diff 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
247254pure @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+
362380version (unittest )
363381{
364382private :
You can’t perform that action at this time.
0 commit comments