I am developing a C ++ interface that allows the user to iterate through objects decoded from a file. This decoding process is somewhat slow.
I am considering an iterator interface for this, but I want to avoid an unnecessary copy, so I am thinking about (user side):
for (const auto& object : file) {
std::cout << object.whatever() << std::endl;
myObjectCopy = object;
myObjectPtr = &object;
}
object in the previous usage example, is a reference to an object internal to the iterator instance.
It is not right? What other idiomatic interfaces would you suggest here?
I thought about the stream interface (I think std::istream), but AFAIK, data reading methods also return copies (they extract characters).