I'd like to wrap a const std::vector<char>&
with a std::istream
to forward to a library function. Various answers like this one recommend creating a class
/ struct
which derives from std::streambuf
and calls the setg
method, but that method only takes in char_type*
, not const char_type*
. This makes sense, as std::streambuf
is designed for both input and output, but that makes using it in a read-only capacity impossible without a couple of const_cast
s. In the <streambuf>
header I don't see any read-only stream buffers (e.g. an istreambuf
) which might enable a std::istream
.
Is there another way to wrap const std::vector<char>&
into a std::istream
which doesn't require a copy, and doesn't use const_cast
?