2015-06-19 67 views
1

對於C++地圖:C++地圖比較聲明如下

map < set<int>,int > x; 

什麼是編譯器使用默認的比較器功能?
我的代碼使用這個語句成功執行,但我不確定它使用的比較器。

+2

正如從[任何文檔】參見(http://en.cppreference.com/w/cpp/container/map)時,比較默認爲'的std :: less 'for std :: map '。這反過來將'<'轉換爲它的參數,''std :: set'](http://en.cppreference.com/w/cpp/container/set/operator_cmp)重載了'operator <'。 –

回答

2

對於默認這個應該下定決心

bool operator<(const std::set<int>&, const std::set<int>&) 

參考見here

3

對於std::map<K, T>,默認比較器爲std::less<K>。使用lhs < rhs作爲比較的默認方式。利用這一點,你可以使用

bool operator<(std::set<int> const& lhs, std::set<int> const& rhs)