Search code examples
c++boostboost-geometryr-tree

Using boost geometry with dimension specified at runtime


The boost::geometry::model::point takes as a compile-time argument the dimension of the point. For instance,

typedef bg::model::point<float, 2, bg::cs::cartesian> point;

Is there any way of specifying the dimension at run time, say, depending on input given to program?

My goal is to use the rtree data structure in boost::geometry::index with arbitrary dimensions. Is it possible to write a custom point class with this feature, or would the type system prevent me from doing this?


Solution

  • There is no way, facilitated by the library.

    You can always employ your own type erasure. This will take some effort, and depending on how it's executed, possibly some performance.

    That's actually also the reason this doesn't "jell" with the library design. The library focuses strongly on performance through genericity.

    Contrary to what you expect this does not support runtime polymorphism, because that would hamper performance. Instead, strictly compiletime polymorphism is used. The compiler can inline and "see through" all the code paths to generate optimal code.