On Jun 22, 2008, at 11:49, Ovanes Markarian wrote:
Does anyone have a suggestion as to how I can get a value out of a boost::any for which I don't know the specific type stored in it? if you know the set of types you operate on consider using boost::variant which supports visitor pattern for dispatching of currently stored type.
Yes, I'll have to look into boost::variant. Thanks for that pointer, all.
Hope that helps. It is difficult to make suggestions, because we don't if you are allowed to modify the interface.
Right. And a very good point to bring up. I am constructing this
100% myself from scratch, so anything *can* be done.
The super-class in which I'm trying to extract this value is a
generic database access object. The boost::any is being returned from
a "get me the value of column X in table Y" method, implemented by any
subclass that implements the database-specific layer. So, the values
could literally be any value that could be stored in any data value in
any database, which is why I was trying to use something very generic.
This particular function, the first I'm implementing in the design
as I'm building it out, is asking for a value it knows will be
effectively boolean. But, depending on the underlying database, may
be an int, or some other type. The first case I'm coding is using an
sqlite3 subclass of the database object, and there is no boolean
type. There is an integer type, and since that database (in current
versions) supports 64-bit integers, I've coded that method to return a
boost::any