### Vector elements

How can I check, if all the elements in a vector are equal to each other or not?
I would make a boolean function.

 ``12345678`` ``````bool vecSame(vector vec) { for(int i = 0; i < vec.size(); ++i) { if(vec[0] != vec[i]) return false; } return true; }``````

Just some algorithmic thinking is all. Basically it keeps comparing the first element to every element in the vector one at a time to make sure they are the same as the first element, (thus, they would all be the same). If it finds an element that doesn't match, it will return false, but if it makes it all the way through the for loop without returning false, it must be true, so there's a return true statement at the end.
Thanks! (:
 ``12345678910111213141516171819`` ``````template bool is_uniform(const std::vector& vec, size_t pos1 = 0, size_t pos2 = 0){ if(vec.empty()) return false; //Because there is nothing to be uniform about else if((pos1 == pos2 && pos1 == 0) || (pos1 > pos2)){ pos2 = vec.size() - 1; pos1 = 0; } if(pos1 == pos2) return true; else if(pos1 + 1 != pos2){ //Avoid checking the second half if possible if(is_uniform(vec, pos1, (pos2-pos1)/2+pos1)) return is_uniform(vec, (pos2-pos1)/2+pos1+1, pos2); else return false; } return vec[pos1] == vec[pos2]; }``````