title: const input vs non-const output
body: <p>I have a function which traverses a tree of objects and does not modify any of the objects in the tree. </p>
  
  <p>The function looks something like this:</p>
  
  <pre><code>static Node* findMatchingNode(const Node&amp; root, const SomeFilterData&amp; d);
  
  struct Node {
     Node* left;
     Node* right;
  };
  </code></pre>
  
  <p>The function can return the root or any object in the tree or nothing. It's obvious than with given declaration I have to perform <em>const_cast</em> somewhere, which is forbidden in most cases. </p>
  
  <p>Is it acceptable for a function to guarantee constness and at the same time allow anyone to modify its output?</p>
  
  <p><em><strong>EDIT</strong>. I haven't stated this clearly, my function really does not modify any of the nodes in the tree, doesn't create new Node, it's pure function. I'd like to always have <code>const</code> qualifier there to tell everyone clearly that the function doesn't modify anything</em></p>
  
  <p><em><strong>EDIT</strong>. The unspoken problem behind is that there is no legal way to express constness of the input during the function execution (and only inside the function) without enforcing the output constness.</em></p>