Skip to content

Add GeometryType::Id to allow using GeometryType as a template parameter

Steffen Müthing requested to merge feature/add-geometrytype-id into master

After thinking about what I proposed in #17 (closed), I realized that an index is probably not the right idea of thinking about this. Instead, we can just do a 1-to-1 mapping of GeometryType to a canonical id, as GeometryType itself is just a 8 byte struct that stores three integral values.

I've nested the id within GeometryType as GeometryType::Id here and added implicit conversions between the two. The id type is a scoped enum to avoid any future nastiness with implicit conversions to other integral types.

With this merge request, you can have a template with a GeometryType parameter with just a tiny bit of overhead on the implementor's side:

// note the additional "::Id"
template<GeometryType::Id gt_>
class Foo
{
  // reconstruct the GeometryType
  static constexpr GeometryType gt = gt_;
};

For the user, it looks like they can just plug in a GeometryType:

Foo<GeometryTypes::triangle> foo;

This solves a major 2.6 headache in PDELab (see #17 (closed), pdelab/dune-pdelab#102), so I'd really like this to go into 2.6.

Closes #17 (closed).

Merge request reports