Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does QMap support custom comparator functions?

Tags:

c++

qt

qmap

I couldn't find a way to set a custom comparator function for QMap, like I can for std::map (the typename _Compare = std::less<_Key> part of its template arguments).

Does QMap have a way to set one?

like image 731
sashoalm Avatar asked Jul 04 '13 07:07

sashoalm


People also ask

Does QNAP support link aggregation?

Set Port Trunking on your QNAP NAS to increase the bandwidth via 802.3ad protocol. Port Trunking, also known as LACP (Link Aggregation Control Protocol), allows you to combine multiple LAN interfaces for increased bandwidth and load balancing for multiple clients.

Why do we need run security counselor on QNAP NAS?

With elevated security threats spreading over the Internet, the Security Counselor checks for weaknesses and offers recommendations to secure your data against multiple attack methods. Security Counselor also integrates anti-virus and anti-malware software to ensure the complete protection of your QNAP NAS.

What does multimedia console do on QNAP?

The Multimedia Console saves you time and effort in multimedia management by allowing you to centrally manage and monitor all of the multimedia apps on QNAP NAS, including setting content source folders and user permissions for each multimedia app.


3 Answers

It's not documented (and it's a mistake, I think), but in you can specialize the qMapLessThanKey template function for your types (cf. the source). That will allow your type to use some other function rather than operator<:

template<> bool qMapLessThanKey<int>(const int &key1, const int &key2) 
{ 
    return key1 > key2;  // sort by operator> !
}

Nonetheless, std::map has the advantage that you can specify a different comparator per each map, while here you can't (all maps using your type must see that specialization, or everything will fall apart).

like image 70
peppe Avatar answered Sep 21 '22 06:09

peppe


No, as far as i know QMap doesn't have that functionality it requires that it's key type to have operator<, so you are stuck with std::map if you really need that compare functionality.

like image 43
Zlatomir Avatar answered Sep 23 '22 06:09

Zlatomir


QMap's key type must provide operator<(). QMap uses it to keep its items sorted, and assumes that two keys x and y are equal if neither x < y nor y < x is true.

In case, overload operator<().

like image 23
asclepix Avatar answered Sep 22 '22 06:09

asclepix