Not too tough:
julia> function f!(A)
for (count, idx) in enumerate(eachindex(A))
A[idx] = count*2
end
end
f! (generic function with 1 method)
julia> f!(A); @allocated f!(A)
0
Or this works as a slightly less-quick sanity check, too:
julia> using BenchmarkTools
julia> function g!(A)
i = 0
for idx in eachindex(A)
i += 1
A[idx] = i*2
end
end
julia> @btime f!($A)
11.029 ns (0 allocations: 0 bytes)
julia> @btime g!($A)
13.349 ns (0 allocations: 0 bytes)
Amusingly, that difference does seem real — your “comfortable” construction is actually slower