title: How to generalize container adaptors with templates?
body: <p>I've got the following class:</p>
  
  <pre><code>#include &lt;set&gt;
  #include &lt;stack&gt;
  #include &lt;queue&gt;
  #include &lt;string&gt;
  
  template &lt;typename T&gt;
  class MySet
  {
      public:
          const std::stack&lt;T&gt; data() const
          {
              std::stack&lt;T&gt; other_cont ( typename std::stack&lt;T&gt;::container_type ( cont.begin(), cont.end() ) );
              return other_cont;
          }
  
      private:
          std::set&lt;T&gt; cont;
  };
  </code></pre>
  
  <p>And the following code:</p>
  
  <pre><code>MySet&lt;std::string&gt; a;
  MySet&lt;int&gt; b;
  
  const std::stack&lt;std::string&gt; s = a.data();
  const std::queue&lt;int&gt; q = b.data();
  </code></pre>
  
  <p>I would like to use one templated member function to initialize any adaptor type.
  So far it only works with either <code>stack</code> or <code>queue</code>, I can't figure out how to use templates to generalize it.</p>
  
  <p>This is what I've tried:</p>
  
  <pre><code>template &lt;template &lt;typename&gt; typename M&gt;
  const M&lt;T&gt; data() const
  {
      M&lt;T&gt; other_cont ( typename M&lt;T&gt;::container_type ( cont.begin(), cont.end() ) );
      return other_cont;
  }
  </code></pre>
  
  <p>Compiler says it can't deduce the template parameter <code>M</code>.</p>