Posts Tagged ‘tips’

Serializing non-default-constructible objects with boost

November 18, 2008

Boost serialization is not trivial for an object that has no default constructor. Consider this:

class Foo
{
public:
	int v1;
	int v2;

	Foo(int v1_) { v1 = v1_; }

	template <typename Archive>
	void serialize(Archive& ar, unsigned int version)
	{
		ar & v1;
		ar & v2;
	}
};

//...
binary_iarchive ar;
Foo foo(0);
ar >> foo;

We only suffer a minor inelegance because of redundantly initializing foo. But what if we need to deserialize a pointer?
Hint: it won’t compile

Using Excel for analysis

November 10, 2008

Excel is a great analysis tool. A lot of people know that creating an Excel-readable report from your program is simple: just write your data into a text file, separating the columns by spaces or tabs. Here are some less-known features:

(more…)