title: Python's None return feature mimicking in C++
body: <p>I like the feature in Python that can return None when it doesn't find the correct return value. For example:   </p>
  
  <pre><code>def get(self, key):
      if key in self.db:
          return self.db[key]
      return None
  </code></pre>
  
  <p>I need to implement the same feature in C++. I think about some possibilities.</p>
  
  <h3>Return true/false, when true get the value from reference or pointer</h3>
  
  <pre><code>bool get(string key, int&amp; result)
  {
      if (in(key, db)) {
          result = db[key];
          return true;
      }
      return false;
  }
  </code></pre>
  
  <h3>Throw an error for notifying None case</h3>
  
  <pre><code>int get(string key) throw (int)
  {
      if (in(key, db)) {
          result = db[key];
          return result;
      }
  
      throw 0;
  }
  
  try {
      ....
  }
  catch (int n)
  {
      cout &lt;&lt; "None";
  }
  </code></pre>
  
  <h3>Use pair</h3>
  
  <pre><code>pair&lt;bool, int&gt; getp(int i)
  {
      if (...) {
          return pair&lt;bool, int&gt;(true, 10);
      }
      return pair&lt;bool,int&gt;(false, 20);
  }
  
  pair&lt;bool, int&gt; res = getp(10);
  if (res.first) {
      cout &lt;&lt; res.second;
  }
  </code></pre>
  
  <p>Which one is normally used in C++? Are there any other ways to do it in C++?</p>