Boost logo

Boost :

From: Ross Smith (r-smith_at_[hidden])
Date: 2001-10-24 22:37:58


David Abrahams wrote:
>
> One nice thing about using unsigned numbers is that detecting errors
> typically requires only one assertion. For example:
>
> T& array<T>::operator[](std::size_t n)
> {
> assert(n < size());
> return data[n];
> }
>
> Of course, that's just a common case and we can't do the same thing for
> shared_ptr.

For me, the main reason I normally use unsigned types for counters
(although I admit this probably isn't relevant to shared_ptr) is to
avoid GCC's warnings about signed-vs-unsigned comparisons in code like
the above (if n was a signed type, GCC would complain about the assert).

(Because I write a lot of cross-platform code that needs to work with
multiple compilers, I tend to be paranoid about standards compliance and
portability, and I have a firm rule that all my code must compile with
g++ -ansi -pedantic -W -Wall -Werror.)

-- 
Ross Smith ...................................... Auckland, New Zealand
r-smith_at_[hidden] ........................ http;//halflife.mani.ac.nz/
        "A wise man learns from the mistakes of others; a fool
        learns only from his own."     -- Gen. Aleksandr Lebed

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