Returning a flexible datatype from a C++ function
<p>I'm developing for a legacy C++ application which uses ODBC for it's data access. Coming from a C# background, I really miss the ADO style of data access.</p>

<p>I'm writing a wrapper (because we can't actually use ADO) to make our data access less painful. This means no <code>char</code> arrays, no manual text blob streaming, and no declaritive column binding.</p>

<p>I'm struggling with how to store / return data values. In C# at least, you can declare an <code>object</code> and cast it to whatever (as long as the type is convertable).</p>

<p>My current C++ solution is to use <code>boost::any</code> to store the data value in a custom <code>DataColumnValue</code> object. This class has conversion and assignment operators to the various types used in our app (more than 10). There's a bit of complexity here because if you store an <code>int</code> in the <code>boost::any</code> and try to <code>boost::any_cast&lt;long&gt;</code> you get a <code>boost::bad_any_cast</code>. Client objects shouldn't have to know how the value is stored internally.</p>

<p>Does anyone have any experience trying to store / return values whose types are only known at runtime? Is there a better / cleaner way?</p>
