Wrap a POD type in arrays Efficiently

I’m trying to add a tag to an Integer which is either 0 or 1 (it will used for indexing, so I’m not using Booleans), which will looks like:

struct Bit{T <: Integer}
    value::T
end

However, this approach will suffer when trying to use an array for indexing, e.g

S = Bit{Int}[Bit(1), Bit(0)]

And then I will need to convert a array of Array{Bit{Int}} to Array{Int} which will allocates another array, is it possible to directly reinterpret the array rather than doing the conversion? like in C++ there is a reinterpret_cast, is there anything similar? Or there is better approach in this?

Why is reinterpret(Int, S) and then working with the reinterpreted array good enough?

1 Like