I've just found in some legacy code a big misuse of a std::distance between iterators of different containers.
Something like the code included. Now I'm afraid that someone may have made the same mistake in other part of the code.
Is there a way to detect this kind of error at compile or runtime ?
// bad code to explain the problem
std::vector<int> v1={1};
auto iterv1=v1.begin();
std::vector<int> v2=v1;
int nDist=std::distance(v2.begin(),iterv1); // error distance calculated between 2 containers