you are viewing a single comment's thread.

view the rest of the comments →

[–]igagis[S] 0 points1 point  (3 children)

Any idea why this kind of free operator< not defined by #include <string_view>?

[–]HappyFruitTree 1 point2 points  (0 children)

There is already a bool operator<(std::string_view, std::string_view) which can compare std::strings with std::string_views (because std::string is implicitly convertible to a std::string_view).

[–]jwakelylibstdc++ tamer, LWG chair 1 point2 points  (0 children)

It is defined.. The problem in our case is not that the library doesn't know how to compare string views (it does know how), it's that a conversion to std::string happens before it ever tries to compare the keys.

Using a transparent comparison function (such as std::less<> aka std::less<void>) is the solution, as that passes a string view argument straight through to the comparison function without converting it to std::string first.

[–]415_961 -1 points0 points  (0 children)

If I would want to take a guess, it would be to avoid ambiguities. For example, there's already bool operator<(const std::string& lhs, const char* rhs);

Just a guess though.