microsoft/Terminal

adjust associative containers to support heterogeneous lookup

開放

#972 建立於 2019年5月24日

 (3 則留言) (1 個反應) (0 位負責人)C++ (9,275 個分叉)batch import
Area-CodeHealthHelp WantedIssue-TaskProduct-Terminal

倉庫指標

星標
 (103,173 顆星)
PR 合併指標
 (平均合併 27天 19小時) (30 天內合併 24 個 PR)

描述

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::string to some value to compare against a const char* or any other type for which an operator< overload is available. It is also useful for indexing composite objects in a std::set by the value of a single member without forcing the user of find to create a dummy object (for example creating an entire struct Person to 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.

貢獻者指南