Boost logo

Boost :

From: me22 (me22.ca_at_[hidden])
Date: 2006-06-29 22:17:57


On 6/29/06, Yuval Ronen <ronen_yuval_at_[hidden]> wrote:
> This warning is not so bad, IMO. It tells you that you are trying
> evaluate a compile-time constant in run-time, and that's wasting CPU
> cycles. The runtime 'if' can be substituted by a compile-time
> specialization.
>
> [...]
>
> This will prevent the compiler from generating the runtime comparison.
> Sure this is a small piece of code we are trying to optimize, and a good
> optimizing compiler would remove it anyway, but if we can write more
> efficient code without relying on a compiler optimization that might or
> might not be there, isn't it better?
>
Surely if a compiler is smart enough to know that a conditional is
constant then it should be able to get rid of the test-and-branch
anyways.

I know that g++ can resolve an if ( boost::is_signed<T>::value ) at
compile-time and only emit code for the branch that is taken. And, of
course, it doesn't have this warning.

~ Scott McMurray


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk