Returning an invalid reference
<p>Sometimes when I'm programming in C++ I wish there was an <code>undefined</code> value for every variable something like Javascript!.
For example when I'm returning a value for out-of-bounds element of an array, it was useful to return an <code>undefined</code> instead of throwing an exception, or:</p>

<pre><code>template &lt;typename T, int SIZE&gt;
class MyArray
{
  T arr[SIZE];
  static T badref;
public:
  T &amp;operator[](int i)
  {
    if (i &gt;=0 &amp;&amp; i &lt; SIZE)
      return arr[i];
    else
      throw std::string("OUT-OF-BOUNDS"); // or: return badref; !!
  }
};
</code></pre>

<p>Another dirty(In my opinion) option is returning a reference of a pre-defind variable as a bad-reference variable. I know we can not assign <code>null</code> or something like that to a reference variable.</p>

<p>Is there an another well formed pattern to return a reference where caller has the ability to find out the returned value is not valid?</p>

<p><strong>EDIT:</strong> I'm not mean a <code>pointer</code></p>
