I wish to compare index of an element in a std::vector to an unsigned value. If I directly compare like;
if(std::distance(...)>min_distance) // true for some
I just get a warning, but works fine. However, to get rid of the warning, if I cast min_distance to int, I do not get any comparison result (although there is)
if(std::distance(...)>(int)min_distance) // never true
What is the exact problem?
Try:
std::distancereturns a signed value. I am assuming you are trying to get the distance in such a way that-2AND2would be considered as2. Theabsfunction gives you the absolute value which means that whatever the sign of the input, you always get a positive value back.