title: Proper C++ way of implementing a lock_guard for custom library
body: <p>O wise interwebs</p>
  
  <p>We have an impasse between two colleagues that we could use your help resolving in the proper C++ way. Basically we have a set of utility classes, two of which are a Mutex and SpinLock class which both have the following abridged interface:</p>
  
  <pre><code>class Mutex {
  public:
      Mutex();
      ~Mutex();
      void Lock();
      void Unlock();
      // ...
  };
  </code></pre>
  
  <p>Obviously this is similar to, but differently-cased than the BasicLockable concept used by std::lock_guard, so we want something similar (assume that the Mutex class is immutable in this example; we cannot add the BasicLockable concept to it). Also not all of our compilers for supported platforms are fully c++11 featured, so we cannot just use vanilla c++11 support.</p>
  
  <p>One school of thought is the following implementation of a generic guard class which can be inherited to provide a generic guard class and inherit from it to create a lock-guard class:</p>
  
  <pre><code>template&lt;class T, void (T::*EnterFn)(), void (T::*ExitFn)()&gt;
  class Guard
  {
  public: // copy constructor deleting omitted for brevity
      Guard( T *lock ) : m_lock(lock) { (m_lock-&gt;*EnterFn)(); }
      ~Guard();                       { (m_lock-&gt;*ExitFn)(); }
  private:
      T *m_lock;
  };
  
  template&lt;class T&gt;
  class LockGuard : public Guard&lt;T, &amp;T::Lock, &amp;T::Unlock&gt;
  {
  public:
      LockGuard(const T* lock) : Guard&lt;T, &amp;T::Lock, &amp;T::Unlock&gt;(lock) {}
  };
  </code></pre>
  
  <p>The other school of thought is to just implement a simple lockguard:</p>
  
  <pre><code>template&lt;class T&gt;
  class LockGuard {
      T* m_lockable;
  public:
      LockGuard(const T* lockable) : m_lockable(lockable) { lockable-&gt;Lock(); }
      ~LockGuard() { m_lockable-&gt;Unlock(); }
  };
  </code></pre>
  
  <p>Which implementation would you choose and why? What is the most proper C++(03, 11, 14, 17) way of implementing it? Is there any inherent value to having a generic Guard class as described above?</p>