Writing your own (naïve) unique_ptr
We will first try a simple, homegrown version of std::unique_ptr<T>. As mentioned at the beginning of this chapter, our goal is to develop an intuition for the kind of code required to write such a type and not to encourage you to try to replace the standard facilities: they exist, they work, they are tested, use them. Oh, and they use many cool tricks we cannot explore in this book as we want to keep the book’s size under control!
Type signature
As mentioned in Chapter 5, unique_ptr<T> does not really exist as the type is, in fact, unique_ptr<T,D>, where D defaults to default_deleter<T>.
We will cover both forms (scalar and array) of unique_ptr. The reason for these two specializations is that for T[], we will want unique_ptr to expose operator[] but we will not want to expose this for a scalar T type.
Let’s start with the basic deleter types we will offer. Note that users can supply other deleter...