title: How to add common functions to template classes?
body: <p>I have two template classes, pseudocode:</p>
  
  <pre><code>template&lt;class L, class M&gt;
  class A
  {
    L l; // copyable
    M m; // only moveable
  }
  
  template&lt;class L, class M&gt;
  class B
  {
    L l;
    M&amp; m_ref;
  
    B(A&amp; a, ExtraParameter ep)
      : l(a.l.subset(ep))
      , m(a.m) {}
  
    // +copy and move constructors and operators
  }
  </code></pre>
  
  <p>(The idea here is to be use <code>B</code>'s as references to parts of <code>A</code>'s. So l might be different, but <code>b.m_ref</code> references an <code>a.m</code>.)</p>
  
  <p>Depending on <code>L</code> and <code>M</code>, I want to add some member functions that are added to both functions. This functions need access to an <code>L</code> and an <code>M</code>. 
  <strong>(how) is this possible?</strong></p>
  
  <p><em>edit: Emphazise the depending on <code>L</code> and <code>M</code>. There will be different combinations of <code>L</code> and <code>M</code> and some allow extra member functions and/or are specialised to use features of <code>L</code> or <code>M</code>.</em></p>
  
  <p>I tried to add these to <code>B</code> and made <code>A</code> a child of <code>B</code>. But I failed to come up with an move-operator for <code>A</code> that updates <code>m_ref</code>.
  <em>edit: I found the move operator by casting <code>this</code> to <code>B</code>. I still do not like this, but I gone close this question, since the problem is solved.</em> </p>
  
  <p>I thought about adding the new member function to a third class template <code>C</code> and make both (<code>A</code> and <code>B</code>) children of <code>C</code>. But I was not able to think of a way to provide the reference to <code>M</code>. CRTP does not seem to fit, since only <code>L</code> and <code>M</code> should be template parameters of <code>C</code>.</p>