Use range iterators in spectral functions