3 ms·
algorithm_signed() and algorithm_unsigned() in the conditional compilation example need to be templated functions for the example to make (more) sense.
by eps 7y ago
algorithm_signed() and algorithm_unsigned() in the conditional compilation example need to be templated functions for the example to make (more) sense.
- saagarjha 7y agoIs algorithm being templated not enough?
- Jaxan 7y agoTwo points. 1) Currently, the code could be written with normal overloading (one for int and one for unsigned). No traits required. 2) The current code relies on an implicit cast to int or unsigned int. I’m not sure that’s good.
- edflsafoiewq 7y ago> Currently, the code could be written with normal overloading (one for int and one for unsigned). No traits required f( (uint8_t)0 ) will dispatch to the overload f(int) with overloads. The type-trait code will dispatch to f_unsigned(unsigned).
- dirtydroog 7y agoI didn't believe you but you're right. The uint8_t gets promoted to int, not unsigned int. https://godbolt.org/z/icQHw3 https://godbolt.org/z/icQHw3
- saagarjha 7y agoC’s integer promotion rules aren’t the best.