Skip to content
Snippets Groups Projects

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

Merged Steffen Müthing requested to merge feature/add-geometrytype-id into master
1 unresolved thread

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

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
300 unsigned char dim_;
302 301
303 302 /** \brief bool if this is none-type */
304 bool none_ : 1;
303 bool none_;
304
305 /** \brief Topology Id element */
306 unsigned int topologyId_;
307
308 // Internal type used for the Id. The exact nature of this type is kept
309 // as an implementation detail on purpose. We use a scoped enum here because scoped enums
310 // can be used as template parameters, but are not implicitly converted to other integral
311 // types by the compiler. That way, we avoid unfortunate implicit conversion chains, e.g.
312 // people trying to work with GlobalGeometryTypeIndex, but forgetting to actually call
313 // GlobalGeometryTypeIndex::index(gt) and just using gt directly.
314 enum class IdType : std::uint64_t
  • uint64_t isn't guaranteed by the standard. uint_fast64_t is.

  • That's true - but do we expect to run on a machine that has 128 bit integers, but no 64 bit integers anytime soon? :wink:

  • But possibly on 32 bit machines that have no native 64 bit types. uint_fast64_t can be a non-native type, uint64_t, if provided, must be supported by the implementation directly.

    Anyway, it's probably not worth revising the MR just for this issue alone.

  • In that case, we want uint64_t - it has to be a native type, otherwise the compiler won't accept it as a template parameter.

  • It must be a fundamental type to be acceptable as a template parameter. I understand "must be supported by the implementation directly" and "native" as the CPU supports it directly. I don't think fundamental types are required to be native types (otherwise the C++11 standard library could not be implemented on i386).

  • Please register or sign in to reply
  • Jö Fahlke
  • Is this now to go into 2.6 - it's not even in master yet but still marked as 2.6 milestone.

  • changed milestone to %DUNE 2.7.0

  • Now, there was way too much discussion about this - I moved the milestone to 2.7.0

  • added 78 commits

    • bb56b770...38586f59 - 76 commits from branch master
    • 95163647 - [GeometryType] Add an integral GeometryType::Id type for use as a template parameter
    • 04302751 - [tests] Add a test for GeometryType::Id

    Compare with previous version

  • mentioned in commit 69e5fd19

  • Please register or sign in to reply
    Loading