Search code examples
c++stdstringstdset

std::set of std::string inequality implementation


Since std::set is implemented as a binary tree, how does it compare std::string for inequality? Does it look like a < b && b < a?

Is it using the length of the string directly or is it hashing it somehow? Does it at all guarantee uniqueness of strings?


Solution

  • std::set uses less to sort its keys. That's operator< on a std::string which compares the strings lexicographically.