title: How can I form a `final` reference to a non-final class?
body: <p><code>final</code> is an excellent keyword. It lets me prevent inheritance from a class. It also lets the compiler skip the runtime dispatch mechanisms when calling virtual functions or accessing virtual bases.</p>
  
  <p>Suppose now that I have some non-<code>final</code> class <code>T</code> with virtual functions and/or base classes. Suppose also that I have a reference to an instance of this class. <strong>How could I tell the compiler that this particular reference is to the fully-derived complete object, and not to a base sub-object of a more derived type?</strong></p>
  
  <p>My motivations are classes like <code>optional</code> and <code>vector</code>. If I invoke <code>optional&lt;T&gt;::operator*()</code>, I get a <code>T&amp;</code>. However, I know with certainty that this reference really is a <code>T</code>, not some more derived object. The same applies to <code>vector&lt;T&gt;</code> and all the ways I have of accessing its elements. </p>
  
  <p>I think it would be a great optimization to skip the dynamic dispatch in such cases, especially in debug mode and on compilers not smart enough to look through the <code>optional</code> and <code>vector</code> implementations and devirtualize the calls.</p>