Boost logo

Boost :

From: johneddy_at_[hidden]
Date: 2001-11-11 21:50:58


The any class is very interesting. I find it very appealing for the
purpose of mixed type containers. Is it necessary to poll the class
for the actual type each time you wish to access the contents (or
poll it for the type and supply the logic to deal with the results)?

For instance, if I wish to print the value held by an "any" class
object to the screen, must I do the following or is there a
different/better way?:

void Print(const boost::any& operand) {

if(operand.type() == typeid(int))
     std::cout << any_ptr<int>(operand) << endl;

else if(operand.type() == typeid(float))
     std::cout << any_ptr<float>(operand) << endl;

else if ...

}


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk