I want a standard C++ container to use as an accumulator for reading from a network socket (that is, T = byte
or unsigned char
). I want the container to reserve a capacity on construction, and not initialize the elements. That is, I want to be able to do:
container c(1024);
and get the container to reserve 1024 octets. One-step construction/capacity is important because I want to use it in an initializer.
I also want contiguous storage. If the containers must grow, the new storage should be contiguous.
I also want to be able to append
bytes to the container. And I want to be able to search for byte strings in the container.
vector
and string
don't really fit because construction and reserve are two step process, they use an extra allocation, and they initialize elements. Plus, vector
is missing the search functionality. (EDIT: vector
is fine thanks to <algorithm>
; thanks DYP and Lightness Races in Orbit).
Are there any C++ standard containers that have the properties?