我现在正在深入boost::iostreams研究,我正在寻找一种方法来创建一个迭代 some 的流container<char>。
现在我有适用于 a 的代码std::vector<char>,但它只适用于它,因为我编写了std::vector特定的代码。
我正在做以下事情:
template <class Object, class Container>
void Load(Object& object, const Container& container) {
using namespace boost::iostreams;
// Create a stream that iterates over vector and use it in
// the following procedure
LoadImpl(object, stream<array_source>(&container[0], container.size()));
}
其中LoadImpl(...)描述如下:
template <class Object
void LoadImpl(Object& object, std::istream& stream) { ... }
并用于使用某些特定stream的 .
你能给我一些关于如何让Load日常工作更通用的建议吗?比方说,我想有能力代替std::vector<char>它,只要有一些std::string容器。