【发布时间】:2014-06-02 22:23:11
【问题描述】:
我正在尝试使用 Boost 序列化库来归档 Boost ICL 间隔集(因为我找不到任何其他或多或少的标准方法来序列化它们)。我想将serialize 函数拆分为两个函数save 和load。很抱歉,我现在被困在load 函数中——我什至无法保存间隔集的大小。
我的测试程序如下。编译器抱怨A << IS.iterative_size() 行,这很奇怪,因为iterative_size() 函数的返回类型是size_t。
#include <fstream>
#include <string>
#include <boost/archive/binary_iarchive.hpp>
#include <boost/archive/binary_oarchive.hpp>
#include <boost/serialization/split_free.hpp>
#include <boost/icl/discrete_interval.hpp>
#include <boost/icl/interval_set.hpp>
const std::string Filename = "tmp.archive";
typedef boost::icl::discrete_interval<int> Interval;
typedef boost::icl::interval_set<int> IntervalSet;
namespace boost
{
namespace serialization
{
template<class Archive>
void save(Archive& A, const IntervalSet& IS, const unsigned int)
{
A << IS.iterative_size();
// ...
}
template<class Archive>
void load(Archive& A, IntervalSet& IS, const unsigned int)
{
// ...
}
template<class Archive>
inline void serialize(Archive& A, IntervalSet& IS, const unsigned int V)
{
split_free(A, IS, V);
}
}
}
int main()
{
std::ofstream f(Filename);
if (f.good())
{
boost::archive::binary_oarchive oa(f);
IntervalSet s;
s += Interval::closed(100, 200);
oa << s;
f.close();
}
else
{
std::cout << "Error" << std::endl;
}
}
有什么想法吗?
(编译器 - GCC 4.8.1,Boost - 1.55.0,操作系统 - Xubuntu 3.11)
【问题讨论】:
标签: c++ serialization boost