The apparent problem is the third parameter,
binary predicate. It should return
true
if the elements are to be considered equal. Two array elements are passed to this predicate function, and you should not make any assumption on what are they. The purpose of this predicate is obvious though. You return true when one element is less than another, and it means that one of these elements is removed, because the interpretation of the predicate is "the elements are equal, so one of the two elements is redundant, so it should be removed".
Please see:
unique — C++ Reference.
Infer the consequences by yourself, or use the debugger to see how the algorithm works; for this purpose, create your own predicate function with two elements, pass it the the algorithm function and set a break point on your predicate function. Possible implementations are shown here:
std::unique — cppreference.com.
Infer the consequences by yourself.
What to do instead? First of all, you need to formulate what you want to achieve precisely. Neither your description nor the sample of data can explain it. It should be mathematically strict formulation. What you want to achieve, by your example, cannot be considered as anything matching the concept of
uniqueness. For example, 14 and 16 are already unique, but you want to remove them. What is it? Anyway, no matter what it is, the algorithm should be different. By the way, what's wrong with writing your own algorithm?
By the way, maybe you can also consider different approach. How do you obtain your input data? You could considering filtering data as you add elements to the vector. If your goals really was uniqueness, the solution would be very obvious. In your case, it depends on what you want to achieve.
—SA