Boost logo

Boost :

From: Sebastian Redl (sebastian.redl_at_[hidden])
Date: 2006-04-18 17:07:33

Jorge Lodos wrote:

>Why not? As long as:
>1. The operator has meaning for holded objects.
>2. The operation can be performed between holded objects
>3. The code won't compile if some not defined (by holded objects) operator
>is used.
But this #3 is exactly why it can't work. Any doesn't know at compile
time which type it might hold. Not even at link time, or even run time.
Any any object may be passed in from a different compilation unit, a
shared library even, one that's dynamically loaded to satisfy my run
time claim. You can perhaps do this with variant, but not with any.

I also think that this is simply a misuse of any. It's not supposed to
be worked with. It's intended for user-supplied data carried along by a
library, like for example the user data in the DOM. (In DOM Level 3,
every DOM node has a string->any map of user data. The DOMUserData type
maps to Object in Java, no type in particular in ECMAScript, and could
conceivably map to boost::any in C++.) This data is only ever held by
the library in its any container. Every access to the data should be
performed by any-casting it back to its original type, which the client
should know. (In the case of DOM, the data is associated with string
keys, so ideally, every string key would always have data of the same type.)
If use of any is restricted to this case, no comparison of anys is ever

Sebastian Redl

Boost list run by bdawes at, gregod at, cpdaniel at, john at