title: Detect common base class
body: <p>Suppose one has a class hierarchy, without multiple inheritance:</p>
  
  <pre><code>struct TOP{};
  struct L : TOP{}; 
  struct R : TOP{};
  struct LL : L{};
  struct LR : L{};
  struct RL : R{};
  struct RR : R{};
  </code></pre>
  
  <p><strong>Is it possible to write a metafunction that will return the type of the common base of two types? (it could return <code>void</code> if not common base class exists.)</strong>
  For example</p>
  
  <pre><code>common_base&lt;RR, R&gt;::type == R
  common_base&lt;RL, RR&gt;::type == R
  common_base&lt;LL, RR&gt;::type == TOP
  common_base&lt;LL, std::string&gt;::type == void
  </code></pre>
  
  <p>Obviously this wouldn't work with multiple inhertance, but I am focused in the the single inheritance case.</p>
  
  <p>First, it doesn't seem to be possible without some introspection of the base class. So, I have this easier problem, do it in such a way that each clase knows its base (by an internal <code>base</code> type), for example:</p>
  
  <pre><code>struct LR : L{using base = L;};
  </code></pre>
  
  <p>Even in this way, I cannot seem to get the metaprogramming right.</p>
  
  <p><em>Also I read somewhere (I can't find it now) that GCC has some extensions to detect common base class. Is that the case?</em></p>