Using std::distance instead of manually static-casting to int