Boost logo

Boost :

From: Michiel Salters (Michiel.Salters_at_[hidden])
Date: 2001-12-03 07:59:17


Consider what happens if you want to compile Print. What operator<<'s should
it be linked with? Your example below makes that clear, but if you don't
enumerate
them, you can't link them in.

Or, to phrase it in another way: there are an infinite number of ways to
print
any<>thing.

HTH,
Michiel Salters

> -----Original Message-----
> From: johneddy_at_[hidden] [mailto:johneddy_at_[hidden]]
> Sent: Monday, November 12, 2001 3:51 AM
> To: boost_at_[hidden]
> Subject: [boost] any class
>
> 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