Copy-on-write pointer for C++