# Simulate Tuple{Vararg{T1,N},T2} where{T1, N, T2}

**URL:** <https://discourse.julialang.org/t/simulate-tuple-vararg-t1-n-t2-where-t1-n-t2/10061>\
**Category:** General Usage\
**Created:** [March 30, 2018, 12:58am UTC](https://discourse.julialang.org/t/simulate-tuple-vararg-t1-n-t2-where-t1-n-t2/10061 "2018-03-30T00:58:26Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![cnliao](https://avatars.discourse-cdn.com/v4/letter/c/ce73a5/32.png) [@cnliao](https://discourse.julialang.org/u/cnliao)\
**Post date:** [March 30, 2018, 12:58am UTC](https://discourse.julialang.org/t/simulate-tuple-vararg-t1-n-t2-where-t1-n-t2/10061/1 "2018-03-30T00:58:26Z")

</div>

It seems that [Vararg is not supported except at last place](https://github.com/JuliaLang/julia/issues/10770), but I want its behavior.  
What I am trying to do is to preallocate a vector of views into an Array, so that each view can be reused instead of having to be recreated many times. The detailed motivation is discussed [here](https://discourse.julialang.org/t/propose-for-a-movable-subarray/10066).

Here is what I wish I could be writing:

```julia
using EllipsisNotation
const SliceAll = Base.Slice{Base.OneTo{Int}}
const View{T, N} = SubArray{T,N-1,Array{T,N},Tuple{Vararg{SliceAll,N-1},Int},true} where {T,N}
struct Views{T,N}
    x::Vector{View{T,N}}
    Views{T,N}(x::AbstractArray{T,N}) = new([view(x, .., i) for i in 1:size(x)[end]])
end

```

So it is the `Tuple{Vararg{SliceAll,N-1},Int}` part that is blocking me now.  
Is there a way around this? Any suggestion appreciated!

---

<div class="post-metadata">

**Author:** ![mbauman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbauman/32/31082_2.png) [@mbauman](https://discourse.julialang.org/u/mbauman)\
**Post date:** [March 30, 2018, 2:58pm UTC](https://discourse.julialang.org/t/simulate-tuple-vararg-t1-n-t2-where-t1-n-t2/10061/2 "2018-03-30T14:58:33Z")

</div>

The standard workaround here is something like this:

```julia
struct Views{V}
    x::V
end
function Views(x::AbstractArray)
    v = [view(x, .., i) for i in 1:size(x)[end]]
    Views{typeof(v)}(v)
end

```

That is, just let Julia figure it out with a less-restrictive type parameter.

---

<div class="post-metadata">

**Author:** ![cnliao](https://avatars.discourse-cdn.com/v4/letter/c/ce73a5/32.png) [@cnliao](https://discourse.julialang.org/u/cnliao)\
**Post date:** [March 31, 2018, 5:56am UTC](https://discourse.julialang.org/t/simulate-tuple-vararg-t1-n-t2-where-t1-n-t2/10061/3 "2018-03-31T05:56:10Z")

</div>

Works!  
I really need to fix my brain and do away the jinx that makes me explicitly type everything…

---

<div class="post-metadata">

**Author:** ![pkofod](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pkofod/32/2179_2.png) [@pkofod](https://discourse.julialang.org/u/pkofod)\
**Post date:** [March 31, 2018, 7:41am UTC](https://discourse.julialang.org/t/simulate-tuple-vararg-t1-n-t2-where-t1-n-t2/10061/4 "2018-03-31T07:41:20Z")

</div>

You’ll feel free like a bird once you do 🙂
