FR: allow URL to be used as key in std::map

As per subject, I guess implementing “URL::operator<” suffices

In the absense of an explicit operator< (the semantics of which would be difficult to define in a meaningful way for all use-cases) you may specify your own comparator function to map/set etc.

struct UrlComparator
{
    bool operator() (const URL& a, const URL& b) const
    {
        return a.toString (true) < b.toString (true);
    }
};

template <typename Value>
using UrlMap = std::map<URL, Value, UrlComparator>;
3 Likes

Thanks for the quick response, yes, I realized the same shortly after posting and was going to delete the post. But it might still be useful for future reference.

Minor syntax matter: the type for the map values has been skipped in your code for UrlMap, the UrlComparator should end as third template argument

Oops thanks, good spot!