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

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

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

問題描述

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

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.

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

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.

推薦答案

密鑰所需要的只是它是可復制和可分配的.映射中的排序由第三個參數定義模板(以及構造函數的參數,如果使用的話).這個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
    {
        //  ...
    }
};

注意它必須定義一個嚴格的排序,即如果 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).

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

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

相關文檔推薦

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++ 中旋轉圖像而不使用 OpenCV 函數)
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 無法設置 SVM 參數)
Convert a single color with cvtColor(使用 cvtColor 轉換單一顏色)
主站蜘蛛池模板: 国产精品国产 | 欧州一区二区三区 | 国产视频第一页 | 欧美在线视频二区 | 亚洲精品久久久久久一区二区 | 久久久久久久久99 | 久久精品国产一区二区电影 | 欧美日韩综合 | 九九九久久国产免费 | 国产视频一区二区 | 91天堂| 久久r久久 | 一区欧美| 韩日在线视频 | 日本成人中文字幕 | 亚洲精品一区二区在线观看 | 人人人人干 | 久久免费精品 | 好姑娘影视在线观看高清 | 日韩中文字幕 | 亚洲a在线观看 | 国产东北一级毛片 | 久久不卡| 国产精品日韩欧美一区二区三区 | 久久精品欧美一区二区三区麻豆 | 一区二区免费 | 国产精品观看 | 亚洲乱码国产乱码精品精的特点 | 欧美大片一区二区 | 最新午夜综合福利视频 | 欧美.com| 国产成人免费在线观看 | 成年人在线观看视频 | 久久久久精 | 久在线 | av乱码| 91精品久久久久久久久中文字幕 | 日日夜夜精品视频 | 色噜噜亚洲男人的天堂 | 黄色成人亚洲 | 欧美精品一区二区三区在线播放 |