title: Which school of reporting function failures is better
body: <p>Very often you have a function, which for given arguments can't generate valid result or it can't perform some tasks. Apart from exceptions, which are not so commonly used in C/C++ world, there are basically two schools of reporting invalid results.</p>
  
  <p>First approach mixes valid returns with a value which does not belong to codomain of a function  (very often -1) and indicates an error</p>
  
  <pre><code>int foo(int arg) {
      if (everything fine)
          return some_value;
      return -1; //on failure
  }
  </code></pre>
  
  <p>The scond approach is to return a function status and pass the result within a reference</p>
  
  <pre><code>bool foo(int arg, int &amp; result) {
       if (everything fine) {
           result = some_value;
           return true;
       }
       return false;  //on failure
  }
  </code></pre>
  
  <p>Which way do you prefer and why. Does additional parameter in the second method bring notable performance overhead?</p>