# User-defined Variadic Parametric Types

**URL:** <https://discourse.julialang.org/t/user-defined-variadic-parametric-types/25487>\
**Category:** General Usage\
**Tags:** parametric-types\
**Created:** [June 20, 2019, 3:34pm UTC](https://discourse.julialang.org/t/user-defined-variadic-parametric-types/25487 "2019-06-20T15:34:55Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![cshenton](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cshenton/32/9326_2.png) [@cshenton](https://discourse.julialang.org/u/cshenton)\
**Post date:** [June 20, 2019, 3:34pm UTC](https://discourse.julialang.org/t/user-defined-variadic-parametric-types/25487/1 "2019-06-20T15:34:56Z")

</div>

In `Base`, `Tuple` can have variadic (0 or more) type arguments.

Is there a way to achieve this for a user defined type?

I want to represent something like a strongly typed reference to a single database row. Where the struct itself holds only a reference to the database and a row number, and the type parameters are for dynamic dispatch and to ensure only available data can be accessed.

(In C++ I would probably use a variadic template for this)

---

<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:** [June 20, 2019, 3:42pm UTC](https://discourse.julialang.org/t/user-defined-variadic-parametric-types/25487/2 "2019-06-20T15:42:35Z")

</div>

You can parameterize a type by a tuple type.

---

<div class="post-metadata">

**Author:** ![cshenton](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cshenton/32/9326_2.png) [@cshenton](https://discourse.julialang.org/u/cshenton)\
**Post date:** [June 20, 2019, 3:47pm UTC](https://discourse.julialang.org/t/user-defined-variadic-parametric-types/25487/3 "2019-06-20T15:47:24Z")

</div>

Could you please give an example? Are you suggesting something like this?:

```julia
struct RowReference{T} where T <: Tuple 
   vals::T
end

```

This doesn’t solve the problem since I don’t want to store instances on the struct itself. I could have a field which is a `Tuple{Vararg{DataType}}` but I want to use this to resolve some stuff at compile time, so that adds unwanted overhead.

---

<div class="post-metadata">

**Author:** ![cshenton](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cshenton/32/9326_2.png) [@cshenton](https://discourse.julialang.org/u/cshenton)\
**Post date:** [June 20, 2019, 3:50pm UTC](https://discourse.julialang.org/t/user-defined-variadic-parametric-types/25487/4 "2019-06-20T15:50:34Z")

</div>

What I want is something more like this (not actual Julia syntax):

```julia
struct RowReference{Ts...}
   db::DB
   rowID::Int 
end

function getindex(r::RowReference{Ts...}, col::U) where U in Ts
    # Look up col number in DB index, grab the element from the DB
end 

```

---

<div class="post-metadata">

**Author:** ![Elrod](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/elrod/32/22461_2.png) [@Elrod](https://discourse.julialang.org/u/Elrod)\
**Post date:** [June 20, 2019, 4:09pm UTC](https://discourse.julialang.org/t/user-defined-variadic-parametric-types/25487/5 "2019-06-20T16:09:29Z")

</div>

> [@cshenton](#):
>
> Could you please give an example?

[StaticArrays](https://github.com/JuliaArrays/StaticArrays.jl/blob/master/src/SArray.jl#L18) use a tuple to give one parameter per axis.
