ska-sa / spead2

Library for the Streaming Protocol for Exchange of Astronomical Data (SPEAD)
http://spead2.readthedocs.io/en/latest/
GNU Lesser General Public License v3.0
23 stars 14 forks source link

Implement range-based for loop over ring_stream #294

Closed bmerry closed 11 months ago

bmerry commented 12 months ago

Previously, the canonical way to iterate over all the received heaps in a ring_stream was:

while (true)
{
    try
    {
        auto heap = stream.pop();
        // Do stuff with heap
    }
    catch (spead2::ringbuffer_stopped &)
    {
        break;
    }
}

With this change, it's possible to rewrite that as

for (auto &&heap : stream)
{
    // Do stuff with heap
}
bmerry commented 11 months ago

@sjperkins thanks for the review. A slight improvement occurred to me in the meantime, which I've just pushed. Could you take a look? It's just a couple of lines.