title: Use of unique_ptr in classes with protected destructors
body: <p>I am studying policy based design from <a href="https://www.amazon.es/Modern-Design-Generic-Programming-Patterns/dp/0201704315" rel="nofollow noreferrer">Modern C++ Design</a>, and I have got stuck in a simple example below, where I was trying to use a <code>std::vector</code> of <code>std::unique_ptr</code>s in my templated policy class:</p>
  
  <pre class="lang-cpp prettyprint-override"><code>#include &lt;memory&gt;
  #include &lt;vector&gt;
  
  template &lt;class T&gt; struct MyPolicy {
    MyPolicy() = default;
    MyPolicy(std::size_t N) : myvec{std::vector&lt;std::unique_ptr&lt;T&gt;&gt;(N)} {
      for (std::size_t i = 0; i &lt; N; i++)
        myvec[i].reset(new T(i));
    }
  
    // protected: // or, even, public:
    //   /*virtual*/ ~MyPolicy() = default;
  
  private:
    std::vector&lt;std::unique_ptr&lt;T&gt;&gt; myvec;
  };
  
  template &lt;class T, template &lt;class&gt; class Policy&gt;
  struct Shell : public Policy&lt;T&gt; {
    Shell() = default;
    Shell(std::size_t N) : Policy&lt;T&gt;(N) {}
  };
  
  int main(int argc, char *argv[]) {
    Shell&lt;double, MyPolicy&gt; s;
    s = Shell&lt;double, MyPolicy&gt;(7);
  
    Shell&lt;double, MyPolicy&gt; s2{6};
    s = std::move(s2);
    return 0;
  }
  </code></pre>
  
  <p>Everything works well above. However, the catch is that since <code>MyPolicy</code> is supposed to be inherited from, its destructor needs to be either <code>virtual</code> and <code>public</code>, or non-<code>virtual</code> and <code>protected</code> (at least, quoting from the book).</p>
  
  <p>In the above example, whenever I uncomment the lines to make them either</p>
  
  <pre class="lang-cpp prettyprint-override"><code>public:
  virtual ~MyPolicy() = default;
  </code></pre>
  
  <p>or</p>
  
  <pre class="lang-cpp prettyprint-override"><code>protected:
  ~MyPolicy() = default;
  </code></pre>
  
  <p>the code does not compile. I cannot understand what the problem related to <code>std::unique_ptr</code> is in this example, since the type <code>T</code> is not incomplete or something that has a protected/private destructor.</p>
  
  <p>I would appreciate your help. Thanks.</p>