|
Boost : |
Subject: Re: [boost] Range-aware version of min and max
From: Neil Groves (neil_at_[hidden])
Date: 2010-01-27 03:28:45
>
> Are there any potential problems with using sizeof() to determine which
> type
> to return? Is there a better method that is more aware of the actual
> ranges
> supported by the types?
>
>
sizeof() is insufficient since we need to know how to promote between for
example, int and unsigned int. There is also the possibility that you might
want to promote from int to double, but whether to allow this becomes
questionable as one reaches the magnitude that suffers loss of precision.
I have an implementation for the common arithmetic types that I would be
prepared to submit.
In my experience of using arithmetic type promotion and demotion it is
often desirable to allow customisation of the promotion policy through a
template parameter while providing a default policy that always preserves
accuracy.
Regards,
Neil Groves
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk