The cppreference shows an example use std::uniqueto remove consecutive spaces from a string:
std::string s = "wanna go to space?";
auto end = std::unique(s.begin(), s.end(), [](char l, char r){
return std::isspace(l) && std::isspace(r) && l == r;
});
std::cout << std::string(s.begin(), end) << '\n';
However, in the requirements section for a unique state
Elements are compared using the given binary predicate p. The behavior is undefined unless it is an equivalence relation.
So my question is: is this example valid? The predicate is clearly not reflective (the two characters "n" are compared unevenly) and, therefore, are not an equivalence relation.
Andre source
share