Listing 1: Extending the LockHolder class and delegating to the policy class

// For brevity, a simplified version is shown here. The complete
// version is available online at <www.cuj.com/code>.
 template <class LockType, class LockingPolicy = ClassicScope>
class Guard : private LockHolder<LockType> {
  friend class LockHolder<LockType>;
public:
  Guard(LockType& lock) : LockHolder<LockType>(lock) {
    LockingPolicy::createScope(*this);
  };
  Guard(Guard& g) : LockHolder<LockType>(g) {
    LockingPolicy::shareScope(*this, g);
  }
  Guard(Guard& g, LockType& lock) : LockHolder<LockType>(lock) {
    LockingPolicy::transferScope(*this, g);
  }
  ~Guard() throw() {
      if(!isDisabled())
        LockingPolicy::destroyScope(*this);
  }
};