Skip to content

Commit

Permalink
Implement comparison operators following IComparable impl.
Browse files Browse the repository at this point in the history
  • Loading branch information
kzu committed Nov 27, 2024
1 parent 61d5035 commit c247fa0
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/StructId/Templates/Comparable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,16 @@
{
/// <inheritdoc/>
public int CompareTo(TSelf other) => Value.CompareTo(other.Value);

/// <inheritdoc/>
public static bool operator <(TSelf left, TSelf right) => left.Value.CompareTo(right.Value) < 0;

/// <inheritdoc/>
public static bool operator <=(TSelf left, TSelf right) => left.Value.CompareTo(right.Value) <= 0;

/// <inheritdoc/>
public static bool operator >(TSelf left, TSelf right) => left.Value.CompareTo(right.Value) > 0;

/// <inheritdoc/>
public static bool operator >=(TSelf left, TSelf right) => left.Value.CompareTo(right.Value) >= 0;
}

0 comments on commit c247fa0

Please sign in to comment.