Array type parameters?

115 views
Skip to first unread message

Amit Lavon

unread,
Jun 6, 2022, 2:33:58 AM6/6/22
to golang-nuts
Hi,
Is it possible to set a generic type parameter of "T array of any size" (not slice)? Something like:
func foo[A [...]T, T constraints.Integer](a A) {
  m := map[A]string{}
  ...
}

Jason Phillips

unread,
Jun 6, 2022, 2:41:03 AM6/6/22
to golang-nuts
Not currently. See the "omissions" section of the proposal [1]:

> No parameterization on non-type values such as constants. This arises most obviously for arrays, where it might sometimes be convenient to write type Matrix[n int] [n][n]float64. It might also sometimes be useful to specify significant values for a container type, such as a default value for elements.


Amit Lavon

unread,
Jun 6, 2022, 1:03:58 PM6/6/22
to golang-nuts
Thank you! That gives me clarity.
Reply all
Reply to author
Forward
0 new messages