adjust associative containers to support heterogeneous lookup
#972 ouverte le 24 mai 2019
Métriques du dépôt
- Stars
- (35 764 stars)
- Métriques de merge PR
- (Merge moyen 27j 19h) (24 PRs mergées en 30 j)
Description
Heterogeneous lookup has been supported since C++14. To quote the linked article,
C++14 allows the lookup to be done via an arbitrary type, so long as the comparison operator can compare that type with the actual key type. This would allow a map from
std::stringto some value to compare against aconst char*or any other type for which anoperator<overload is available. It is also useful for indexing composite objects in astd::setby the value of a single member without forcing the user offindto create a dummy object (for example creating an entirestruct Personto find a person by name).
Now, it's magic in that you enable it by specifying std::less<> as the third template argument to an associative container; that is:
std::map<std::string, std::string > map1;
std::map<std::string, std::string, std::less<>> map2;
map2 supports heterogeneous lookup, whereas map1 does not.