gpt4 book ai didi

c++ - 可搜索输入过滤器定义

转载 作者:行者123 更新时间:2023-11-30 05:29:27 24 4
gpt4 key购买 nike

使用 boost,我需要一个可搜索的输入过滤器,它将对从 ifstream 读取的字节进行操作。这是我目前拥有的:

struct my_filter : boost::iostreams::seekable_filter
{
template<typename Source>
int get(Source& src)
{
int byte = boost::iostreams::get(src);
if(byte != EOF && byte != boost::iostreams::WOULD_BLOCK)
{
// Do something with byte
}
return byte;
}

template<typename Sink>
bool put(Sink&, char)
{
// No need to actually implement put because this filter is only used with ifstream
return true;
}

template<typename T>
std::streampos seek(T& t, boost::iostreams::stream_offset off, std::ios_base::seekdir way, std::ios_base::openmode which = std::ios_base::in | std::ios_base::out)
{
return boost::iostreams::seek(t, off, way, which);
}
};

它有效,但我想摆脱无用的 put 方法。这里的 boost 文档 http://www.boost.org/doc/libs/1_60_0/libs/iostreams/doc/concepts/filter.html说有一个 Filter 的 InputSeekableFilter 改进,但我似乎无法理解如何使用它(没有我可以使用的 input_seekable_filter_tag 或 input_seekable_filter 结构)。

最佳答案

llonesmiz 在 boost-users 上的回答:

"boost::iostreams::seekable_filter" seems to just be a typedef for "boost::iostreams::filter<boost::iostreams::seekable>". I don't know for sure, but I think it would make sense that deriving your "struct my_filter" from "boost::iostreams::filter<boost::iostreams::input_seekable>" would accomplish what you want.

关于c++ - 可搜索输入过滤器定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36387112/

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