Skip to content

Conversation

@daleonov
Copy link

I was quite surprised to discover that I can't use juce::File as a key in std::unordered_map. Obviously, the workaround is to just use a string with file's full path, but I believe it's an extra string allocation and copy, plus clutters the code, if you don't need that string for anything else. Also, it's possible to mix up relative and absolute paths by accident, which using the actual file object will help to avoid.

I've laid it out in a similar manner to juce::String and juce::UUID, as they already have std::hash implementation. The actual hash function for 64-bit value was already there, so that's what I've used.

Usage:

std::unordered_map<juce::File, int> someMap;
// ...
const int x = someMap.at (someFile);

instead of:

std::unordered_map<juce::String, int> someMap;
// ...
const int x = someMap.at (someFile.getFullPathName());

Adds compatibility with STL hash maps and hash sets
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant