Like the question says, I’m wondering about the reason for that. Because I get an error when I try to get the distance between const and non-const iterators.
vector<int> v;
auto it=v.begin();
auto cit=v.cbegin();
distance(it,cit);
no matching function for call to ‘distance(__gnu_cxx::__normal_iterator<int*, std::vector<int> >&, __gnu_cxx::__normal_iterator<const int*, std::vector<int> >&)
From my limited understanding of iterators, I see no reason why it shouldn’t work.
You have a mutable iterator and a constant iterator in the call to
std::distance, so template argument deduction is failing. You can fix this by specifying the template argument explicitly.