gpt4 book ai didi

c++ - boost::iostreams::filtering_stream 的底层流的类型是什么?

转载 作者:搜寻专家 更新时间:2023-10-31 01:47:57 25 4
gpt4 key购买 nike

我有这个使用 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com