Slide 34
Slide 34 text
Template
%{
integerBinaryOps = [
(x[:-1], x[-1], x[:-1].capitalize(), 'a result')
for x in 'add+ subtract- multiply* divide/'.split()
] + [ ('remainder', '%', 'Divide', 'the remainder') ]
}%
Usage
public protocol _IntegerArithmeticType {
% for name,_,Action,result in integerBinaryOps:
/// ${Action} `lhs` and `rhs`, returning ${result} and a `Bool` that is
/// true iff the operation caused an arithmetic overflow.
static func ${name}WithOverflow(lhs: Self, _ rhs: Self) -> (Self, overflow: Bool)
% end
}