Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <unordered_map>
- #include <boost/utility/string_view.hpp>
- #include <boost/functional/hash.hpp>
- using namespace std;
- // custom specialization of boost::hash
- namespace boost
- {
- template<>
- struct hash<boost::string_view>
- {
- std::size_t operator()(boost::string_view str) const
- {
- return boost::hash_range<const char*>(str.begin(), str.end());
- }
- };
- }
- namespace test
- {
- class example
- {
- public:
- void check()
- {
- m["abc"] = 123;
- m["def"] = 456;
- }
- void print()
- {
- for (auto& elem : m)
- std::cout << elem.first << ":" << elem.second << std::endl;
- }
- private:
- std::unordered_map<boost::string_view, std::size_t, boost::hash<boost::string_view>> m;
- };
- }
- int main() {
- test::example p;
- p.check();
- p.print();
- return 0;
- }
Add Comment
Please, Sign In to add comment