Refactoring to a unique handle

Now, to ease our programming process, we will create a class named NullHandle that will automatically release the resource each time we no longer need it. It will be constructed from the UniqueHandle class, which we will develop as well. These classes can be found in the uniquehandle.h file. The implementation of UniqueHandle is as follows:

    template <typename C>    class UniqueHandle    {      private:        HANDLE m_val;        void Close()        {          if (*this)          {            C::Exit(m_val);          }        }      public:        // Copy assignment operator         UniqueHandle(UniqueHandle const &) = delete;        auto operator=(UniqueHandle const &)->UniqueHandle & = delete;        // UniqueHandle constructor        explicit UniqueHandle(HANDLE value = C::Invalid()) :        m_val{ value }        {        } // Move assignment ...

Get Learning C++ Functional Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.