c++ - boost::unordered_set of char16_t strings -


why following

#include <string> #include <boost/unordered_set.hpp>  int main() {         typedef boost::unordered_set<std::string> unordered_set;     unordered_set animals;      animals.emplace("cat");     animals.emplace("shark");     animals.emplace("spider");     return 0; } 

work , following results in many compilation errors.

#include <string> #include <boost/unordered_set.hpp>  int main() {         typedef boost::unordered_set<std::u16string> unordered_set;     unordered_set animals;      animals.emplace("cat");     animals.emplace("shark");     animals.emplace("spider");     return 0; } 

also, what's solution ? need write own hash_function , operator== in function objects mentioned here ?

the operator== not concern, because defined in standard library. however, hash function has adapted std::hash specialization std::u16string provided standard library, work std::unordered_* containers, not boost's ones.

one solution might define hashing function in following way:

std::size_t hash_value(std::u16string const &s) {     return std::hash<std::u16string>{}(s); } 

this wrapper written logic wrapped work nicely boost.

lastly, let me remind of availability of equivalent std::unordered_set container in c++11 standard library, in case didn't know it.


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -