上QQ阅读APP看书,第一时间看更新
Equivalence
We can also implement the == operator, since again it makes sense to be able to compare two GridMovement objects:
extension GridMovement
{
static prefix func -><- (movement: inout GridMovement)
-> GridMovement
{
return GridMovement (rows: movement.col, cols: movement.row)
}
}
These GridMovement objects are usable now as, say, chessboard moves that can be added together, multiplied by an integral number of moves, and compared with each other. Now go write a chess program.
Just kidding.