Migrate from boost::unordered_map to std::unordered_map#3107
Migrate from boost::unordered_map to std::unordered_map#3107SergioRAgostinho merged 2 commits intoPointCloudLibrary:masterfrom
boost::unordered_map to std::unordered_map#3107Conversation
| } | ||
| }; | ||
| typedef boost::unordered_multimap<HashKeyStruct, std::pair<size_t, size_t> > FeatureHashMapType; | ||
| typedef std::unordered_multimap<HashKeyStruct, std::pair<size_t, size_t>, boost::hash<HashKeyStruct>> FeatureHashMapType; |
There was a problem hiding this comment.
The std library does not expose hashing specializations for containers. Since we're still using boost, I leveraged it.
There was a problem hiding this comment.
Unfortunately, does not seem to work and I don't have any other proposals. Maybe leave boost::unordered_multimap for now?
There was a problem hiding this comment.
I haven't got back to this once I created the PR. I have one alternative in mind but I still need to look with special care to the error message.
Note that in cppreference even mentions boost::hash for hashing the std::pair container.
Note: additional specializations for std::pair and the standard container types, as well as utility functions to compose hashes are available in boost.hash
Source: https://en.cppreference.com/w/cpp/utility/hash
| }; | ||
|
|
||
| typedef boost::unordered_map<int, Leaf, boost::hash<int>, std::equal_to<int>, Eigen::aligned_allocator<int> > HashMap; | ||
| typedef std::unordered_map<int, Leaf, std::hash<int>, std::equal_to<int>, Eigen::aligned_allocator<std::pair<const int, Leaf>>> HashMap; |
There was a problem hiding this comment.
This allocator looked suspicious. The convention is to allocate the full object that will be created. The moment it started using std::unordered_map, it triggered a static assertion which complained it was not a valid allocator, so now it's changed to conform with the default.
| const std::size_t h2 = std::hash<int>{} (s.second.first); | ||
| const std::size_t h3 = std::hash<int>{} (s.second.second.first); | ||
| const std::size_t h4 = std::hash<int>{} (s.second.second.second); | ||
| return h1 ^ (h2 << 1) ^ (h3 << 2) ^ (h4 << 3); |
There was a problem hiding this comment.
Alternatively, we can cast HashKeyStruct to a std::pair<int, std::pair<int, std::pair<int, int>>> here and return the output of boost::hash.
There was a problem hiding this comment.
Yes, but to me looks good as it is now.
boost::unordered_map to std::unordered_map
No description provided.