Add GeometryType::Id to allow using GeometryType as a template parameter
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
Activity
This relies on !86 (merged) for the storage layout, I'll rebase the MR once that is merged.
mentioned in merge request !86 (merged)
mentioned in issue #17 (closed)
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 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).
- Resolved by Jö Fahlke
changed milestone to %DUNE 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
-
bb56b770...38586f59 - 76 commits from branch
mentioned in commit 69e5fd19