Is NaN a valid key value for associative containers?
Consider the ordered and unordered associative containers in C++ keyed on double . Is NaN a valid key type? With ordered containers, I should say "no", because it does not respect the strict weak ordering. With unordered containers, I have no idea. Here's what happens in GCC 4.6.2: #include <map> #include <unordered_map> #include <cmath> #include <iostream> #include <prettyprint.hpp> int main() { typedef std::map<double, int> map_type; // replace by "unorderd_map" map_type dm; double d = std::acos(5); // a good nan dm[d] = 2; dm[d] = 5; dm[d] = 7; std::cout << "dm[NaN] = " << dm[d] << ", dm =