pub const CompareOperator = enum pub fn reverse(op: CompareOperator) CompareOperatorReverse the direction of the comparison. Use when swapping the left and right hand operands.
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653pub const CompareOperator = enum {
/// Less than (`<`)
lt,
/// Less than or equal (`<=`)
lte,
/// Equal (`==`)
eq,
/// Greater than or equal (`>=`)
gte,
/// Greater than (`>`)
gt,
/// Not equal (`!=`)
neq,
/// Reverse the direction of the comparison.
/// Use when swapping the left and right hand operands.
pub fn reverse(op: CompareOperator) CompareOperator {
return switch (op) {
.lt => .gt,
.lte => .gte,
.gt => .lt,
.gte => .lte,
.eq => .eq,
.neq => .neq,
};
}
test reverse {
inline for (@typeInfo(CompareOperator).@"enum".field_values) |op_field_value| {
const op = @as(CompareOperator, @fromBackingInt(@intCast(op_field_value)));
try testing.expect(compare(2, op, 3) == compare(3, op.reverse(), 2));
try testing.expect(compare(3, op, 3) == compare(3, op.reverse(), 3));
try testing.expect(compare(4, op, 3) == compare(3, op.reverse(), 4));
}
}
}
See also
Order.