[swift-users] generic *= operator
Jan E. Schotsman
jeschot at xs4all.nl
Mon Mar 21 06:54:41 CDT 2016
Hello,
I can define a custom *= operator like this:
func *=( inout lhs:UInt32, rhs:Float )->UInt32
{
lhs = UInt32( roundf( Float(lhs)*rhs ) )
}
but my attempts to make this generic have failed.
I would like something like
func *=<X:SomeIntegerProtocol,Y:SomeFloatProtocol>( inout X, rhs:Y)-> X
{
lhs = X( (Y(lhs)*rhs).round() )
}
that works for all integer types and all floating point types.
Is this feasible?
Jan E.
More information about the swift-users
mailing list