I have a vector
of priority_queue
s of string
s:
vector<priority_queue<string>>> queues(VECTOR_CAPACITY);
And the question is how can I apply custom string
comparator to those priority_queue
s?
Should this be relevant, the comparator I want puts shorter strings before longer ones and when they're equal length uses standard strings comparison.
I tried this way:
auto comparator = [] (string s1, string s2) { return s1.length() < s2.length() || s1 < s2; };
vector<priority_queue<string, vector<string>, decltype(comparator)>> queues(VECTOR_CAPACITY);
but it doesn't compile with the following error:
No matching constructor for initialization of 'value_compare' (aka '(lambda at Example.cpp:202:23)')
EDIT: Comparator that puts shorter strings before longer ones and when they're equal length uses standard lexicographic comparison looks like that:
auto comparator = [] (string s1, string s2)
{
if (s1.length() != s2.length())
{
return s1.length() > s2.length();
}
return s1.compare(s2) > 0;
};