我有一个使用 Boost.Iostreams 执行解压缩的流:
struct istream_zlib
: public boost::iostreams::filtering_stream<boost::iostreams::input, char>
{
istream_zlib(std::istream& in)
{
push(boost::iostreams::zlib_decompressor());
push(in);
}
};
现在,我想稍后访问底层流(std::istream& in
)。天真地,我认为通过 component()
请求 std::istream
就可以了,但我得到的指针是 null
:
auto ptr = component<std::istream>(1); // ptr is null!
我应该向 component()
提供什么类型来执行此操作?
最佳答案
这不是真的,因为不是istream
将被插入filtering_stream
(例如,对于我的 boost 1.48,它将是 boost::iostreams::detail::mode_adapter<boost::iostreams::input, std::istream>
),您可以通过 component_type
检查它的类型。功能。但是,我不知道为什么你需要获取 stream
来自filtering_stream
,因为您发送了引用 - 您应该在使用此 filtering_stream
的地方拥有此对象.
此外,您还可以使用reference_wrapper
对于这种情况(即 push(boost::ref(in));
),然后使用组件获取它
auto ptr = component<boost::reference_wrapper<std::istream>>(1);
关于c++ - boost::iostreams::filtering_stream 的底层流的类型是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18587560/