I want to get the distinct values of a vector of real numbers and keep their order. For example: [1, -1, 5, -1] -> [1, -1, 5]. What I did so far:
std::vector<double> getDistinctValues(const std::vector<double>& data)
{
std::unordered_set<double> distinct(data.begin(), data.end());
std::vector<double> result(distinct.begin(), distinct.end());
return result;
}
This solution doesn't keep the order.