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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.