I am writing a unit test for something which ends up putting a vector of values into a set like so:
std::size_t n = 1e5;
float vec_value = 1;
std::vector<float> data(n, vec_value);
std::unordered_set<float> s;
for (auto x : data) {
s.insert(x);
}
This works fine when the vector has a non-nan value. However, if the vector is nan, the program just hangs and never completes:
std::size_t n = 1e5;
float vec_value = std::numeric_limits<float>::quiet_NaN();
std::vector<float> data(n, vec_value);
std::unordered_set<float> s;
for (auto x : data) {
s.insert(x);
}
even if I use:
std::unordered_set<float> s(data.begin(), data.end());
The program doesnt finish.
Ive put this minimal example into godbolt and I get the same behaviour and I dont know why this happens.
If i lower the number of points down to 1e3/1e4 then it works fine. As soon as I go 1e5 and above points, the program never finishes.