maybeSort

Might or might not sort a range, depending on some static properties of a range.

  • If already sorted and no predicate then no op
  • If not already sorted and no predicate then sort(range) is called
  • If not already sorted and a predicate is provided then sort!pred(range) is called
  • Else it's a no op and you get back the same range you passed in
  • ref
    maybeSort
    (
    alias less = null
    Range
    )
    (
    auto ref Range range
    )

    Examples

    1 import bolts.range: isSortedRange;
    2 
    3 struct A { // unsortable
    4     int i;
    5 }
    6 
    7 struct B { // sortable
    8     int i;
    9     bool opCmp(B a) {
    10         return i < a.i;
    11     }
    12 }
    13 
    14 static assert( isSortedRange!([1].maybeSort));
    15 static assert(!isSortedRange!([A()].maybeSort));
    16 static assert( isSortedRange!([B()].maybeSort));
    17 static assert( isSortedRange!([A()].maybeSort!"a.i < b.i"));

    Meta

    Since

    0.0.1