# \[ANN\] StrongArrays: arrays with strongly-typed indices

**URL:** https://discourse.julialang.org/t/ann-strongarrays-arrays-with-strongly-typed-indices/56588
**Category:** Package Announcements
**Created:** [March 5, 2021, 9:25pm UTC](https://discourse.julialang.org/t/ann-strongarrays-arrays-with-strongly-typed-indices/56588 "2021-03-05T21:25:52Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![circonflexe](https://avatars.discourse-cdn.com/v4/letter/c/c57346/32.png) [@circonflexe](https://discourse.julialang.org/u/circonflexe)
#### Post date: [March 5, 2021, 9:25pm UTC](https://discourse.julialang.org/t/ann-strongarrays-arrays-with-strongly-typed-indices/56588/1 "2021-03-05T21:25:52Z")

</div>

This tiny package allows defining custom array types that use type-aliases of `Int` as their indices. When handling a big data structure with lots of indices, this prevents you from accidentally using the wrong index. (Well, it does not _prevent_ it, but it prevents the code from compiling). Since each index potentially has its own type, this also allows you to use method dispatch to have the right function operate on the right index type. And strongly-typed indices also make the semantics of your code clearer.

The basic interface is quite simple:

```julia
using StrongArrays
@StrongInt MyIndex # creates a type alias for `Int`
MyVector = StrongVector{MyIndex}
V = MyVector([8, 13, 21])
V[1] # throws an exception
V[MyIndex(1)] # returns 8

```

(there is a longer and more complete example in the project’s README, linked below).

The basic indexing, iteration and broadcast operations are also supported; e.g. you can extract a slice, iterate over `pairs()`, or add two arrays. (On the other hand, matrix multiplication – for compatible index types – is not implemented yet).

Since everything is written using trivial wrappers over the basic `AbstractArray` functions, there should be no performance hit — this package is supposed to be of concern only to the compiler!

[The package is here](https://github.com/plut/StrongArrays.jl), it was just submitted for registration.  
(Although I’m not quite completely satisfied with the name; I chose this one because `ArraysWithStronglyTypedIndices` seemed a bit too cumbersome).
