Just browsing through the Boost docs, and I came across a very interesting type,
boost::any. It is basically a variant type that's a hell of a lot safer than a union. (and more flexible i believe) On the examples page, they also have an example of a key/value pair class with boost::any as the 'value' type, allowing you to set arbitrarily-typed values.