cast result of std::distance to unsigned to avoid warning