Function maybeSort

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

auto ref auto maybeSort(alias less, Range) (
  auto ref Range 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
  • Since

    0.0.1

    Example

    import bolts.range: isSortedRange;
    
    struct A { // unsortable
        int i;
    }
    
    struct B { // sortable
        int i;
        bool opCmp(B a) const {
            return i < a.i;
        }
    }
    
    static assert( isSortedRange!([1].maybeSort));
    static assert(!isSortedRange!([A()].maybeSort));
    static assert( isSortedRange!([B()].maybeSort));
    static assert( isSortedRange!([A()].maybeSort!"a.i < b.i"));