Boost logo

Boost :

From: David Abrahams (david.abrahams_at_[hidden])
Date: 2001-10-24 14:50:00


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.

===================================================
  David Abrahams, C++ library designer for hire
 resume: http://users.rcn.com/abrahams/resume.html

        C++ Booster (http://www.boost.org)
          email: david.abrahams_at_[hidden]
===================================================

----- Original Message -----
From: "James Curran/MVP" <jamescurran_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Wednesday, October 24, 2001 2:54 PM
Subject: [boost] Re: shared_ptr doesn't use unsigned reference count?

> I'm not sure I buy that in this case. Shared_ptr has an edge
> condition at zero by its very nature. Doing something at count =
> 0xFFFFFFFF that should have been done at count = 0x00000000 is just
> wrong, and considering 0xFFFFFFF a small negative number rather than a
> large positive number doesn't make it any more or less wrong.
>
> So, by making the count unsigned, we would be formalizing the
> precondition that is already there.
>
> Truth,
> James Curran
>
> -----Original Message-----
>
> Message: 3
> Date: Tue, 23 Oct 2001 22:20:54 -0700
> From: Darin Adler <darin_at_[hidden]>
> Subject: Re: shared_ptr doesn't use unsigned reference count?
>
> That leaves us with reason 3, clarity.
>
> Many C and C++ programmers prefer to avoid the pitfalls of
> unsigned
> arithmetic -- having the edge of the numeric range right next to
> 0 makes it easier to write incorrect code. These programmers don't
> consider clarity reason enough to use an unsigned type, and only use
> an unsigned integer type when either reason 1 or 2 applies.
>
> Let me turn your question around.
>
> Can anyone tell me a practical advantage that would result from
> making
> shared_ptr's pn member be unsigned?
>
>
>
> Info: http://www.boost.org Unsubscribe:
<mailto:boost-unsubscribe_at_[hidden]>
>
> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
>
>
>


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