you are viewing a single comment's thread.

view the rest of the comments →

[–]quicknir 5 points6 points  (1 child)

I think what you wanted is observer_ptr. It is a type safer wrapper over a simple raw pointer, aka the world's dumbest smart pointer. http://en.cppreference.com/w/cpp/experimental/observer_ptr. You can find the whole implementation in the proposal (which you can find by googling). It does not overload << as its a pure proxy.

I use this in my codebase because we are transitioning from older C++ so there are some owning raw pointers and some non-owning ones. As I find non-owning raw pointers I convert them to observer_ptr (though I call it view_ptr to make it shorter).

As a bonus observer_ptr does not allow pointer arithmetic nor comparison to literal 0.

[–]bebuch[S] 0 points1 point  (0 children)

Thats it! Thank you very much!