swift 比较运算符方法

2021-12-09  本文已影响0人  我会回来的

swift 比较运算符方法

代码如下:

// FIXME: comparison operators with optionals were removed from the Swift Standard Libary.

// Consider refactoring the code to use the non-optional operators.

func< (lhs: T?,rhs: T?) ->Bool{

    switch(lhs, rhs) {

    caselet(l?, r?):

        returnl < r

    case(nil, _?):

        return true

    default:

        return false

    }

}

// FIXME: comparison operators with optionals were removed from the Swift Standard Libary.

// Consider refactoring the code to use the non-optional operators.

func<= (lhs: T?,rhs: T?) ->Bool{

    switch(lhs, rhs) {

    caselet(l?, r?):

        returnl <= r

    default:

        return!(rhs < lhs)

    }

}

// FIXME: comparison operators with optionals were removed from the Swift Standard Libary.

// Consider refactoring the code to use the non-optional operators.

func> (lhs: T?,rhs: T?) ->Bool{

    switch(lhs, rhs) {

    caselet(l?, r?):

        returnl > r

    default:

        returnrhs < lhs

    }

}

// FIXME: comparison operators with optionals were removed from the Swift Standard Libary.

// Consider refactoring the code to use the non-optional operators.

func>= (lhs: T?,rhs: T?) ->Bool{

    switch(lhs, rhs) {

    caselet(l?, r?):

        returnl >= r

    default:

        return!(lhs < rhs)

    }

}

上一篇 下一篇

猜你喜欢

热点阅读