Skip to content
volt
GitHub

std::compare

Eq and cmp, the methods std's collections and algorithms compare values with. Every type with == and < has them here; a type of your own attaches its own (eq(this: T&, other: T&) -> bool, cmp(this: T&, other: T&) -> i32), and those win over these.

Source: std/compare.volt

Methods on other types

Attached to built-in types, or to every type (T).

<T: type> attach fn eq(this: T&, other: T&) -> bool

whether this and other are equal, by ==

<T: type> attach fn eq(this: T?&, other: T?&) -> bool

optionals: both empty, or both holding equal values

<T: type> attach fn eq(this: T[..]&, other: T[..]&) -> bool

slices: as long, and equal element by element. Integers and bools compare as bytes, all at once (floats can't: NaN isn't equal to itself, and -0.0 is equal to 0.0)

<T: type> attach fn cmp(this: T&, other: T&) -> i32

-1, 0 or 1: how this sorts against other, by <

attach fn cmp(this: str&, other: str&) -> i32

str sorts byte by byte (see str's cmp in std::text)