-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Migrate from boost::unordered_map
to std::unordered_map
#3107
Migrate from boost::unordered_map
to std::unordered_map
#3107
Conversation
@@ -64,7 +66,7 @@ namespace pcl | |||
this->second.second.second = d; | |||
} | |||
}; | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
@@ -92,7 +94,7 @@ namespace pcl | |||
Eigen::Vector3f vect_at_grid_pt; | |||
}; | |||
|
|||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but to me looks good as it is now.
boost::unordered_map
to std::unordered_map
No description provided.