←back to thread

611 points LorenDB | 1 comments | | HN request time: 0.406s | source
Show context
grumbel ◴[] No.43908210[source]
There is '-Wconversion' to catch things like this. It will however not trigger in this specific case since g++ assumes converting 1000.0 to 1000 is ok due to no loss in precision.

Quantity(100) is counterproductive here, as that doesn't narrow the type, it does the opposite, it casts whatever value is given to the type, so even Quantity(100.5) will still work, while just plain 100.5 would have given an error with '-Wconversion'.

replies(2): >>43908438 #>>43908555 #
1. Arnavion ◴[] No.43908438[source]
The reason to introduce the Quantity wrapper is to not be able to swap the quantity and price arguments.