map insert:class as key,class as value

时间:2016-09-05 03:56:45

标签: c++ stdmap

我有两个类StorageAddress和PersistentChunk。我定义了一个名为SsdChunkMap的地图。

typedef std::map<StorageAddress, PersistentChunk> SsdChunkMap;
SsdChunkMap* _SsdChunkMap;

我想将数据插入地图。

StorageAddress _StorageAddress(victim._addr);
PersistentChunk _PersistentChunk(victim._hdr.pos.offs, victim._data,
            victim._hdr.compressedSize);
    _SsdChunkMap->insert(make_pair(_StorageAddress, _PersistentChunk));

我重载了运算符&lt;

  inline bool operator < (StorageAddress const& other) const
    {
        if(attId != other.attId)
        {
            return attId < other.attId;
        }
        if (coords.size() != other.coords.size())
        {
            return coords.size() < other.coords.size();
        }
        for (size_t i = 0, n = coords.size(); i < n; i++)
        {
            if (coords[i] != other.coords[i])
            {
                return coords[i] < other.coords[i];
            }
        }
        if (arrId != other.arrId)
        {
            //note: reverse ordering to keep most-recent versions at the front of the map
            return arrId > other.arrId;
        }
        return false;
    }

_SsdChunkMap-&gt; insert(make_pair(_StorageAddress,_PersistentChunk));

所以,这是对的吗?

0 个答案:

没有答案