# \`@forward\` on vectors

**URL:** <https://discourse.julialang.org/t/forward-on-vectors/93121>\
**Category:** New to Julia\
**Tags:** question\
**Created:** [January 17, 2023, 11:34pm UTC](https://discourse.julialang.org/t/forward-on-vectors/93121 "2023-01-17T23:34:57Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [January 18, 2023, 7:58pm UTC](https://discourse.julialang.org/t/forward-on-vectors/93121/4 "2023-01-18T19:58:02Z")

</div>

> [@smartalecH](#):
>
> Suppose I was building a system matrix with `GeometryPrimitives.jl`. The package exports an abstract `Shape`, along with various shape subtypes, like `Cylinder`, `Cube`, etc. Importantly, it also exports some useful functions, like `KDTree`, and even overloads `findfirst` to operate on a _vector_ of `Shape` types.

In that particular case, `Shape` is an abstract type, so one approach would be to simply declare a subtype that adds metadata, but contains another shape and delegates to it for geometric primitives. Then it will work fine with array methods.

In the case of this particular package, I would caution you that we found in hindsight that working with a `Vector{<:Shape}` performs poorly. See this discussion on a related topic: [Allocation and slow down when # of types involved increase (slower than C++ virtual methods) - #2 by jling](https://discourse.julialang.org/t/allocation-and-slow-down-when-of-types-involved-increase-slower-than-c-virtual-methods/87656/2) … I’ve been meaning to re-work it with something like the approach in [GitHub - YingboMa/Unityper.jl](https://github.com/YingboMa/Unityper.jl), emulating C `union` types to avoid the general case of dynamic dispatch.

I would also say that the KDTree implementation in that package might be better off returning an index into an array of shapes, so that you can simply store metadata about each shape in another array. In general, I think that this package needs some re-working and the difficulty of using it with metadata is a symptom of that.

---

_[View the full topic](https://discourse.julialang.org/t/forward-on-vectors/93121)._
