title: C++ function to tell whether a given function is injective
body: <p>This might seem like a weird question, but how would I create a C++ function that tells whether a given C++ function that takes as a parameter a variable of type X and returns a variable of type X, is injective in the space of machine representation of those variables, i.e. never returns the same variable for two different variables passed to it? </p>
  
  <p>(For those of you who weren't Math majors, maybe check out this page if you're still confused about the definition of injective: <a href="http://en.wikipedia.org/wiki/Injective_function" rel="nofollow">http://en.wikipedia.org/wiki/Injective_function</a>)</p>
  
  <p>For instance, the function </p>
  
  <pre><code>double square(double x) { return x*x}; 
  </code></pre>
  
  <p>is not injective since <code>square(2.0)</code> = <code>square(-2.0)</code>, </p>
  
  <p>but the function </p>
  
  <pre><code>double cube(double x) { return x*x*x};
  </code></pre>
  
  <p>is, obviously.</p>
  
  <p>The goal is to create a function </p>
  
  <pre><code> template &lt;typename T&gt;
   bool is_injective(T(*foo)(T))
   {
      /* Create a set std::set&lt;T&gt; retVals;
         For each element x of type T: 
         if x is in retVals, return false;
         if x is not in retVals, add it to retVals;
         Return true if we made it through the above loop.
      */
   }
  </code></pre>
  
  <p>I think I can implement that procedure except that I'm not sure how to iterate through every element of type T. How do I accomplish that?</p>
  
  <p>Also, what problems might arise in trying to create such a function? </p>