I suspect that line https://github.com/boostorg/iostreams/blob/develop/example/container_device.hpp#L135 should not contain the "- 1"
When I compare behaviour of stream based on container_device<std::string> with std::stringstream we can see that they show different behaviours:
https://godbolt.org/z/cfq5fM6M6