title: Boost Geometry: Templating BOOST_GEOMETRY_REGISTER_BOX_2D_4VALUES
body: <p>I would like to use R-tree in the Boost Geometry package to construct a spatial index. I would like to use my own Box (CRectangle) data structure as I'm using a third-party library for polygon operations. </p>
  
  <p>To begin, I followed this tutorial on registering custom point/box types. <a href="http://www.boost.org/doc/libs/1_55_0/libs/geometry/doc/html/geometry/reference/adapted/register/boost_geometry_register_box_2d_4values.html" rel="nofollow">http://www.boost.org/doc/libs/1_55_0/libs/geometry/doc/html/geometry/reference/adapted/register/boost_geometry_register_box_2d_4values.html</a></p>
  
  <p>I arrived at the following (simplified) code, which works OK. I get a correct area of 4.</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;boost/geometry.hpp&gt;
  #include &lt;boost/geometry/index/rtree.hpp&gt;
  #include &lt;boost/geometry/geometries/register/point.hpp&gt;
  #include &lt;boost/geometry/geometries/register/box.hpp&gt;
  
  namespace bg  = boost::geometry;
  namespace bgi = boost::geometry::index;
  
  struct dummy_pt
  {
      int x,y;
  };
  
  class CRectangle
  {
   private:
     int xmin, xmax, ymin, ymax;
  
   public:
     // implementation not shown.
     int xmin();
     int ymin();
     int xmax();
     int ymax();
  }
  
  BOOST_GEOMETRY_REGISTER_POINT_2D(dummy_pt, int, bg::cs::cartesian, x, y)
  BOOST_GEOMETRY_REGISTER_BOX_2D_4VALUES(CRectangle, dummy_pt, xmin(), ymin(), xmax(), ymax())
  
  int main(int argc, char** argv)
  {
      CRectangle x = bg::make&lt;CRectangle&gt;(0,0,2,2);
      std::cout &lt;&lt; "Area: " &lt;&lt; bg::area(x) &lt;&lt; std::endl;
      return 0;
  }
  </code></pre>
  
  <p>My problem is how do I register CRectangle if it is templated? That is,</p>
  
  <pre><code>template &lt;typename T&gt;
  class CRectangle 
  {
    public:
      T xmin();
      T xmax();
      T ymin();
      T ymax();
  
    private: 
      T xmin,xmax,ymin,ymax;
  }
  </code></pre>
  
  <p>Here, I could use:</p>
  
  <pre><code>CRectangle&lt;int&gt; or CRectangle&lt;double&gt;
  </code></pre>
  
  <p>I know there is 
  BOOST_GEOMETRY_REGISTER_BOX_TEMPLATED() but that requires lowerLeft() and upperRight() functions. In my case, the CRectangle class will not have these methods since it is coming form a third-party library. </p>
  
  <p>I could write a subclass and provide these two methods, but I would like to know if it possible to use templated classes with BOOST_GEOMETRY_REGISTER_BOX_2D_4VALUES or some other simple way?</p>
  
  <p>Thank you for any suggestions/ideas.</p>