Merge pull request #33 from lioncash/transparent

hecl/hecl: Allow CaseInsensitiveCompare to be used with heterogenous lookup
This commit is contained in:
Phillip Stephens 2020-03-03 16:44:55 -08:00 committed by GitHub
commit 4f045dd0fa
1 changed files with 3 additions and 0 deletions

View File

@ -505,6 +505,9 @@ public:
* @brief Case-insensitive comparator for std::map sorting
*/
struct CaseInsensitiveCompare {
// Allow heterogenous lookup with maps that use this comparator.
using is_transparent = void;
bool operator()(std::string_view lhs, std::string_view rhs) const {
return std::lexicographical_compare(lhs.begin(), lhs.end(), rhs.begin(), rhs.end(), [](char lhs, char rhs) {
return std::tolower(static_cast<unsigned char>(lhs)) < std::tolower(static_cast<unsigned char>(rhs));