diff --git a/src/ifcgeom/AbstractKernel.h b/src/ifcgeom/AbstractKernel.h index 26d6f090b8..87a6e4d623 100644 --- a/src/ifcgeom/AbstractKernel.h +++ b/src/ifcgeom/AbstractKernel.h @@ -102,14 +102,27 @@ namespace { } }; + template + struct TupleTypeIndex; + + template + struct TupleTypeIndex> { + static const std::size_t value = 0; + }; + + template + struct TupleTypeIndex> { + static const std::size_t value = 1 + TupleTypeIndex>::value; + }; + /* A compile-time for loop over the curve kinds */ template struct dispatch_curve_creation { static bool dispatch(const ifcopenshell::geometry::taxonomy::ptr item, T& visitor) { - // @todo it should be possible to eliminate this dynamic_cast when there is a static equivalent to kind() - auto v = ifcopenshell::geometry::taxonomy::template dcast>(item); - if (v && item->kind() == v->kind()) { - visitor(v); + constexpr auto KindIndex = TupleTypeIndex, ifcopenshell::geometry::taxonomy::impl::KindsTuple>::value; + if (item->kind() == KindIndex) { + auto concrete_item = ifcopenshell::geometry::taxonomy::template cast>(item); + visitor(concrete_item); return true; } else { return dispatch_curve_creation::dispatch(item, visitor);