map::find
利用map::key_comp
來搜索關鍵字。默認map::key_comp
適用於我猜測的數據類型。 我有一個對象指針std::map<A*, B*)
的地圖,並希望找到一個對象指針A
。 是否可以重載map :: key以便我可以使用乾淨的map::find
語義?如果是這樣,怎麼樣? 據我所知,std::find_if
可能是一個使用,但我只是想知道,如果這個選項是可能的。重載map :: key_comp,以便我可以在對象指針的地圖上使用map :: find
我想重載map::key_comp
的另一個原因是,對於用戶創建的類,默認比較沒有任何意義。所以std::map
不能按照我希望的方式按鍵排序(使用我的對象比較邏輯)。