Restrict type of value type parameter

I think that NTuple per se does not check that N is an integer, Vararg (which it is aliased to) does.

For structs, the recommended solution is to check in the inner constructor, eg

struct A{L}
    function A{L}() where L
        @assert L isa Integer
        new{L}()
    end
end

A(L::Integer) = A{L}()          # convenience constructor

A(1)                            # OK
A("a fish")                     # error
4 Likes