#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);
}
};
Containers such as map
has iterators that returns a reference to a pair. But how does that even work? If I am writing an iterator to a container, I need to return references to values. But how do I do that if the values are in pairs? And what if I need to slightly modify the data in creating that pair, as in the example above?
I hope my question isn't too confused. Please help!