[swift-users] Exceptional values in the Comparable protocol

Martin R martinr448 at gmail.com
Sun Jul 9 06:39:51 CDT 2017


The Comparable protocol requires that < and == impose a strict total order: exactly one of a==b, a<b, a>b must hold for all values a and b of a conforming type.

But it is also noted that a conforming type may contain a subset of „exceptional values“ which do not take part in the strict total order (such as FloatingPoint.nan).

What does that mean for functions taking comparable arguments, e.g.

    func mySuperSort<T: Comparable>(a: inout [T]) { }

Can the function implementation assume that all values passed to it take part in the strict total order? In other words: „exceptional values“ must not be passed to the function?

Or must the function take that case into account and must not assume that exactly one of a==b, a<b, a>b holds for any arguments passed to it?

Regards, Martin






More information about the swift-users mailing list