Eltype vs typeof what is the difference?

Hey Julianners,

I want to understand what is the use of eltype.
Is it always equal with:
x not iterable: eltype(x) == typeof(x)
x is iterable: eltype(x) == typeof(x[1]) and some size checking?

Or eltype if specifically for empty iterables?

1 Like

typeof(x) give the type of x, but, if x is a container, eltype gives you the type of its contained elements.

6 Likes

Don’t think of the type of the elements of a container this way: it only makes sense if the type of all elements is the same and that type is concrete so it can’t have any subtypes.

2 Likes

Thank you for the answer! I just didn’t understand weather there is something more.

1 Like