久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

std::map 鍵類必須滿足哪些要求才能成為有效鍵?

What requirements must std::map key classes meet to be valid keys?(std::map 鍵類必須滿足哪些要求才能成為有效鍵?)
本文介紹了std::map 鍵類必須滿足哪些要求才能成為有效鍵?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

我想將給定類的對象映射到另一個類的對象.然而,我想用作鍵的類不是我寫的,它是一個簡單的 struct 和幾個值.std::map 對它的內(nèi)容進行排序,我想知道它是如何做到的,以及是否可以將任意類用作鍵,或者是否需要定義一組要求(運算符等等).

I want to map objects of a given class to objects of another. The class I want to use as key, however, was not written by me and is a simple struct with a few values. std::map orders it's contents, and I was wondering how it does it, and if any arbitrary class can be used as a key or if there's a set of requirements (operators and what not) that need to be defined.

如果是這樣,我可以為實現(xiàn)運算符映射使用的類創(chuàng)建一個包裝器.我只需要知道我需要首先實現(xiàn)什么,并且沒有任何引用我 在線找到指定它們.

If so, I could create a wrapper for the class implementing the operators map uses. I just need to know what I need to implement first, and none of the references for the class I found online specify them.

推薦答案

密鑰所需要的只是它是可復(fù)制和可分配的.映射中的排序由第三個參數(shù)定義模板(以及構(gòu)造函數(shù)的參數(shù),如果使用的話).這個defaultsstd::less,默認為 < 操作符,但沒有要求使用默認值.寫個對比運算符(最好作為功能對象):

All that is required of the key is that it be copiable and assignable. The ordering within the map is defined by the third argument to the template (and the argument to the constructor, if used). This defaults to std::less<KeyType>, which defaults to the < operator, but there's no requirement to use the defaults. Just write a comparison operator (preferably as a functional object):

struct CmpMyType
{
    bool operator()( MyType const& lhs, MyType const& rhs ) const
    {
        //  ...
    }
};

注意它必須定義一個嚴(yán)格的排序,即如果 CmpMyType()( a, b) 返回真,則 CmpMyType()( b, a ) 必須返回假,如果兩者都返回false,元素被認為是相等的(成員相同的等價類).

Note that it must define a strict ordering, i.e. if CmpMyType()( a, b ) returns true, then CmpMyType()( b, a ) must return false, and if both return false, the elements are considered equal (members of the same equivalence class).

這篇關(guān)于std::map 鍵類必須滿足哪些要求才能成為有效鍵?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Assertion failed (size.widthgt;0 amp;amp; size.heightgt;0)(斷言失敗(size.width0 amp;amp; size.height0))
Rotate an image in C++ without using OpenCV functions(在 C++ 中旋轉(zhuǎn)圖像而不使用 OpenCV 函數(shù))
OpenCV: process every frame(OpenCV:處理每一幀)
Why can#39;t I open avi video in openCV?(為什么我不能在 openCV 中打開 avi 視頻?)
OpenCV unable to set up SVM Parameters(OpenCV 無法設(shè)置 SVM 參數(shù))
Convert a single color with cvtColor(使用 cvtColor 轉(zhuǎn)換單一顏色)
主站蜘蛛池模板: 中文字幕乱码一区二区三区 | eeuss国产一区二区三区四区 | 国产成人免费视频 | 五月婷婷丁香 | 日韩中出 | 亚洲高清免费 | 欧美激情在线精品一区二区三区 | 亚洲欧美一区二区三区在线 | 99视频久| 国产免费拔擦拔擦8x高清 | 综合久久综合久久 | 四虎成人在线播放 | 国产精品乱码一区二区三区 | 久久精品手机视频 | 亚洲成人精品视频 | 午夜av电影院 | 老头搡老女人毛片视频在线看 | 欧美久久久久久久久中文字幕 | 99久久精品国产一区二区三区 | 91视频18| 欧美激情免费在线 | 亚洲视频二区 | 一级黄色片毛片 | 国产精品国产精品国产专区不卡 | 日本成人福利视频 | 精品国产91亚洲一区二区三区www | 日韩精品在线视频免费观看 | 欧美精品欧美精品系列 | 欧美日韩亚洲三区 | 一区二区三区精品视频 | 久久黄视频 | 97视频在线免费 | 亚洲毛片在线观看 | 国产在线精品一区二区 | 欧美精品在线免费观看 | 午夜视频网站 | 99视频免费在线 | 一区二区三区不卡视频 | 蜜臀久久 | 成人精品一区二区 | 成人福利视频网站 |