C++ class that can be put *only* on the stack?
<p>How can one create a C++ class whose objects can be put <em>only</em> on the stack, as single instances, but </p>

<ul>
<li><em>not</em> into a <code>std::vector</code> (or other std container) and also <em>not</em> in a plain array no matter where these are allocated.</li>
<li><em>not</em> on the heap (answer linked to)</li>
<li><em>not</em> as member into another object, if that object itself lives in a container or in the free store.</li>
</ul>

<p>Note: <a href="https://stackoverflow.com/questions/124856/how-do-i-prevent-a-class-from-being-allocated-via-the-new-operator-id-like">How do I prevent a class from being allocated via the &#39;new&#39; operator? (I&#39;d like to ensure my RAII class is always allocated on the stack.)</a> asks how to avoid the free store, but that's only half the answer. I guess(?) for containers, one can do something similar with the placement-new operator, but what's with arrays and the data-member case?</p>

<p>The restriction should be compiler-enforced. (No runtime checking.)</p>

<p>By example:</p>

<pre><code>class User {
  ...
  StackOnly m; // may be OK (depending if below implementable)
};

void f() {
  StackOnly obj; //ok
  StackOnly arrobj[42]; // fail!
  StackOnly* pObj = new StackOnly(); // fail!
  std::vector&lt;StackOnly&gt; v; // fail!

  User obj; //ok
  User arrobj[42]; // fail!
  User* pObj = new StackOnly(); // fail!
  std::vector&lt;User&gt; v; // fail!
}
</code></pre>