2

我有这个使用 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稍后访问底层流 ( )。天真地,我认为请求std::istream通过component()会做到这一点,但我得到的指针是null

auto ptr = component<std::istream>(1); // ptr is null!

我应该为此提供什么类型component()

4

1 回答 1

3

这不是真的,因为 notistream将被推入filtering_stream(例如,对于我的 boost 1.48,它将是),您可以按功能boost::iostreams::detail::mode_adapter<boost::iostreams::input, std::istream>检查它的类型。component_type但是,我不知道为什么需要streamfrom filtering_stream,因为您发送参考 - 您应该在使用 this 的地方拥有这个对象filtering_stream

此外,您可以使用reference_wrapper这种情况(即push(boost::ref(in));),然后通过组件使用

auto ptr = component<boost::reference_wrapper<std::istream>>(1);
于 2013-09-03T09:00:42.383 回答