Is there a C ++ STL class that works like a pipe?

In abstract terms, a pipe is a stream / FIFO style container with destructive reading. It has a read() method that copies pieces of data at the same time and performs functions such as get and put for single bytes. When read or get returned, data that was copied from the channel is deleted from the internal buffer of the channel — unlike a file or any other type of container.

Most (all?) STL containers do not provide a similar read() command for the buffer command. Is there a fifo container type with pop_many() element?

stringstream is the closest I can think of, as it supports an internal read pointer, and future reads are blocked until the stream is full again. The container is empty from an API perspective, but the data consumed must be manually collected.

Is there an equivalent container or stream class in C ++ that does this, or is it a roll-your-own question (like an example string)?

+6
source share
1 answer

Comments have already mentioned std::deque , which at first glance seems to be your best bet.

If this does not work for you, how about using std::list<std::vector<unsigned char> > . You put pieces one vector at a time, and you splice go to another list when you pop up. You will need to provide a small convenience code for convenience, and this may not be enough if you do not want to immediately read all the elements of one of the subvectors.

+1
source

Source: https://habr.com/ru/post/922934/


All Articles