Debug Pointer: a quick overview

Let’s focus on some keypoints of my debug_ptr:

struct ThrowPolicy {
    ThrowPolicy() {
        throw std::runtime_error("lost reference to undeleted object");
    }
};
struct PrintPolicy {
    PrintPolicy() {
        std::cerr << "WARNING: lost reference "
                        "to undeleted object" << std::endl;
    }
};
#ifndef ENABLE_DEBUG_TYPES
#define typedef_pointer(Type, Alias, ...) typedef Type Alias
#define typedef_array(Type, Alias, ...) typedef Type Alias
#else // ENABLE_DEBUG_TYPES
...
#endif
typedef_pointer(int*, int_p);
int_p p = new int(0);
int_p p_other = new int(0);
*p = 63;
int_p p_other = p;
delete p_other;
operator deleter*() const {
    return deleter::new_deleter(pd_);
}

And that’s all folks!

If you have any question, just leave a comment. If you like this project, or have any other ideas about what could be the next step of the debug_ptr, fork the project on github and have fun :)

git clone git://github.com/cybercase/debug_ptr.git # clone the repo
cd debug_ptr
g++ -Wall -o test debug_ptr_test.cc -DENABLE_DEBUG_TYPES
./test

–01/09/2012