use a bit of C++ stl style iterator