linear iterator
merged implementation of template