Pebble Coding

ソフトウェアエンジニアによるIT技術、数学の備忘録

2017-05-17から1日間の記事一覧

swift3 IntegerArithmaticプロトコル

IntegerArithmeticプロトコルを実装するには、以下8つの関数を定義する必要がある。 最初の2つはComparableである。 static func ==(lhs: M, rhs: M) -> Bool static func <(lhs: M, rhs: M) -> Bool static func addWithOverflow(_ lhs: M, _ rhs: M) -> (…

swift3 Comparableプロトロル

Comparableプロトコルを作るには、 static func <(lhs: Even, rhs: Even) -> Bool static func ==(lhs: Even, rhs: Even) -> Bool の2つを実装すればよい。 struct M : Comparable { var val:Int static func <(lhs: M, rhs: M) -> Bool { return lhs.val <…

swift3 Collectionプロトコル

Collectionプロトコルを作るには、 startIndexプロパティ,endIndexプロパティ,subscript,index(after:) の4つを実装する必要がある。 Collection - Swift Standard Library | Apple Developer Documentation ここでは奇数を返すコレクションOddを作ってみた…