
Hi, Is boost::any suitable to use it as a type of field of record? Record is a set of fields. Every field may store value of different type: int, double, char*. Usually, in this case I'd use union of int,double and char*. But I'd like to solve it a better way, more C++ than C. So, would you recommend boost::any as a type of field value? Cheers -- Mateusz Łoskot http://mateusz.loskot.net

Mateusz Łoskot wrote:
Hi,
Is boost::any suitable to use it as a type of field of record? Record is a set of fields. Every field may store value of different type: int, double, char*.
Usually, in this case I'd use union of int,double and char*. But I'd like to solve it a better way, more C++ than C.
So, would you recommend boost::any as a type of field value?
The boost::any class is more of a modern replacement for void * than it is for a discrete set of types which are usually placed in a union. Try boost::variant for the latter.

Edward Diener wrote:
Mateusz Łoskot wrote:
Hi,
Is boost::any suitable to use it as a type of field of record? Record is a set of fields. Every field may store value of different type: int, double, char*.
Usually, in this case I'd use union of int,double and char*. But I'd like to solve it a better way, more C++ than C.
So, would you recommend boost::any as a type of field value?
The boost::any class is more of a modern replacement for void * than it is for a discrete set of types which are usually placed in a union. Try boost::variant for the latter.
I understand it. I was hinted with Boost.Any by the example of property definition: name-value pair in the docs. It suggested me possible solution, something like: fieldname->fieldvalue. But I'm going to try Boost.Variant now. Cheers -- Mateusz Łoskot http://mateusz.loskot.net

Edward Diener wrote:
Mateusz Łoskot wrote:
Usually, in this case I'd use union of int,double and char*. But I'd like to solve it a better way, more C++ than C.
So, would you recommend boost::any as a type of field value?
The boost::any class is more of a modern replacement for void * than it is for a discrete set of types which are usually placed in a union. Try boost::variant for the latter.
Unfortunately, Boost.Variant can not be compiled by eVC++ 4.0 :-( I think I have to do some magic with Boost.Any, because this one works with eVC++. eVC++ does not support many newer template specialization features. Cheers -- Mateusz Łoskot http://mateusz.loskot.net
participants (2)
-
Edward Diener
-
Mateusz Łoskot