#include <cstdint>
#include <utility>
class SimpleMap {
public:
typedef std::pair<const uint32_t, const uint32_t> value_type;
static const int SIZE = 8;
uint64_t data_[SIZE];
SimpleMap() { data_ = {0}; }
// Returning a reference to the contained data.
uint64_t const& GetRawData(size_t index) {
return data_[index];
}
// Would like to return a pair reference to modified data, but how?
// The following wont work: returning reference to temporary
value_type const& GetData(size_t index) {
return value_type(data_[index] >> 32, data_[index] & 0xffffffff);
}
};
などのコンテナmap
には、ペアへの参照を返すイテレータがあります。しかし、それはどのように機能しますか?コンテナにイテレータを書き込んでいる場合は、値への参照を返す必要があります。しかし、値がペアの場合、どうすればよいですか?そして、上記の例のように、そのペアを作成する際にデータをわずかに変更する必要がある場合はどうなりますか?
私の質問があまり混乱していないことを願っています。助けてください!