Copy from safe-ptr project on Google Code