Boost logo

Boost Users :

From: Jason Winnebeck (yg-boost-users_at_[hidden])
Date: 2003-08-12 07:52:43

Peter Dimov wrote:
> shared_ptr has recently been accepted into the Library Technical Report:

Wow.. That's quite a read. The amount of work you Boost guys put into
all of the subtle details is amazing. I found it quite interesting but
what I was looking for was some rationale on not allowing comparing
shared_ptr to NULL.

Typically when I compare pointers, I often like to compare it like "if (
ptr != NULL )" explictly. I like this for three reasons:

1. It strongly shows that you are testing a pointer.
2. It reads better in terms of saying what you want.
3. I program in Java where it's required, so I'm in the habit ;).

Although I do see some reasons why shared_ptr doesn't allow this test:

1. "As Close to Raw Pointers as Possible, but no Closer"
2. shared_ptrs after reset or default construction are "empty", a
    different concept than from "storing NULL".
3. If you allow a comparsion to NULL ( or 0 ), then the code
    "if ( mySharedPtr == myInt )" will compile but will make no sense.

Is that pretty much the line of thinking there?

Jason Winnebeck

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at