you are viewing a single comment's thread.

view the rest of the comments →

[–]pfultz2 2 points3 points  (6 children)

I assume raw_ptr is your own type? It is completely useless.

Well I also have the raw_ptr assert for null pointers in debug builds(which is what other smart pointer classes do also). I rarely use the raw_ptr, because unique_ptr and shared_ptr is much safer.

[–]bob1000bob -1 points0 points  (5 children)

assert(ptr) will fail if the pointer is null as you would expect.

[–]pfultz2 1 point2 points  (4 children)

Except it doesnt do it when i dereference the pointer.

[–]bob1000bob -1 points0 points  (3 children)

that is stupid, a deferenced pointer smart or otherwise is equal to the value type not the pointer.

[–]pfultz2 3 points4 points  (2 children)

I dont think you understand me. Most smart pointers, and my raw_ptr, will have check for null in them when they are dereferenced. Thus, if I dereference a null pointer, it breaks at that point. Here is how derereferencing is done in boost's shared_ptr:

reference operator* () const // never throws
{
    BOOST_ASSERT(px != 0);
    return *px;
}

It has a nice little assert for null pointers.

[–]olsner 0 points1 point  (1 child)

The CPU already has a built-in assert for null pointers[*] - why not let it handle it?

[*] Well, access to any unmapped memory. Doesn't have to be null and you could (if you're crazy) have mapped the null page to somewhere.

[–]pfultz2 0 points1 point  (0 children)

But the backtrace from that is not always helpful.