title: Trouble with boost::tuple in boost::unordered_map within a templated class
body: <p>I've written a method which automatically interpolates an expensive 2D function in C++.  I'm now trying to allow the class to accept a function pointer so that any function can be interpolated.  To do this, it appears I need a templated class so that I can template it for each object which it needs to evaluate the function pointer upon.  That part is not so bad after I realized I need to define the class entirely in the header so that the linker can template out the class for each object needed.  Now the rub.</p>
  
  <p>Within the class I use boost::unordered_map to store function evaluations so that I don't unnecessarily call the function.  During the interpolation I refine a grid so that it sufficiently describes it (based upon its curvature).  I'm locally subdividing the mesh, so that if my original points were at x=0, .5, 1, the next set might be x=0, .25, .5, 1, where I would only need to evaluate at x = .25 for the second pass.  That's working on its own with a hard coded function, in place of the dynamic function pointer.</p>
  
  <p>The trouble I am having is in defining the necessary operator and hash_value functions for the boost::tuple.  If I put it in the header they are defined multiple times (for each include of the header).  If I try and compile it as an object and link it in, the linker fails to find the definitions.  The two definitions I need to reference in the class:</p>
  
  <pre><code>bool operator==(const BoostTuple2D &amp;a, const BoostTuple2D &amp;b)
  {
      return a.tuple.get&lt;0&gt;() == b.tuple.get&lt;0&gt;() &amp;&amp;
              a.tuple.get&lt;1&gt;() == b.tuple.get&lt;1&gt;();
  }
  
  std::size_t hash_value(const BoostTuple2D &amp;e)
  {
      std::size_t seed = 0;
      boost::hash_combine(seed, e.tuple.get&lt;0&gt;());
      boost::hash_combine(seed, e.tuple.get&lt;1&gt;());
      return seed;
  }
  </code></pre>
  
  <p>In my header I have a struct and typedef:</p>
  
  <pre><code>struct BoostTuple2D {
      BoostTuple2D(double x1, double x2)
          : tuple(x1, x2) {}
      boost::tuples::tuple&lt;double, double&gt; tuple;
  };
  
  typedef boost::unordered_map&lt; BoostTuple2D, double &gt; BoostTuple2DMap;
  </code></pre>
  
  <p>Which is just above my templated class, with ommitions:</p>
  
  <pre><code>template&lt;class F&gt;
  class Interpolate {
  public:
      class Evaluate { 
      // this class uses the map to cache evaluations of the dynamic pointer
          }
  
      Interpolate (double (F::*f)(double, double), F &amp; obj, [...]) : f(f), object(obj), ... {};
  
  private:
      // members
  };
  </code></pre>
  
  <p>How can I make the operator== and hash_value methods available to the class without defining them multiple times?  I am guarding the header file.  I am a c++ newbee, so hopefully its something simple I'm not getting.  Thanks!</p>