Although it is not formally defined, the concept of archive doesn't include the ability to detect the end.
Archives should be self-contained in a sense: you should be deterministically able just to read (deserialize) the correct amount of data because that information is itself part of the archive.
boost::archive::text_iarchive iarch(ifs);
int size;
iach >> size;
for(int i = 0; i != size; ++i) {
T temp;
iarch >> temp;
...//do something with temp
}
As you can see, there is no unbounded while loop.
There is a certain logic that distinguishes an archive from some arbitrary stream of data, even if the syntax looks similar.
Having said that, for some archives, and if you have access to the underlying stream, you can check for the end of the stream.
boost::archive::text_iarchive iarch(ifs);
while(ifs) {
T temp;
iarch >> temp;
...//do something with temp
}
However, big HOWEVER, this breaks the abstraction of the archive, and it will not work for archives that have tags (like XML archives) because the last entry of the archive doesn't necessarily coincide with the end of the underlying stream.
Once you relax the abstraction of the archive, even the concrete one, you try to read tea leaves.
If you are trying to read streams using archives facilities, you might be in better shape by inverting the logic and interpreting the stream as a bunch of archives instead.
... stream logic to get to the point where an archive starts
while(ifs) {
{
boost::archive::text_iarchive iarch(ifs, boost::archive::no_header);
T temp;
iarch >> temp; // using archive deserialization, not low level stream reading
}
... stream logic to process until the next "archive" starts, possibly break
}
In this way, you are not breaking the archive abstraction, at least not directly; the stream is not manipulated directly when the archive abstraction is alive.
If it sounds complicated, it is because it is, and this because you are trying to hack your way in.