Boost logo

Boost :

From: Ed Brey (brey_at_[hidden])
Date: 2000-11-07 10:18:22


I think "any" should be accepted into boost.

I have some issues for improvement of "any" that have not been addressed,
AFAIK, in previous posts:

1. I like exception vs. non-exception tradeoff with any_cast and copy_to.
There are enough use cases where type mismatches are exceptional versus not,
that it is quite worthwhile having both interfaces. I'd like to take the
concept one step further and propose a to_ref method. It would be similar
to to_ptr, except would return a reference and would throw upon trouble
(much like dynamic_cast). In cases where type mismatch is exceptional,
to_ref is more appropriate than to_ptr, since to_ref avoids giving the user
a pointer that he's not allowed to delete.

2. The documentation should state that the user cannot delete the object
pointed to by the return value of to_ptr.

3. bad_any_cast should become any::bad_cast. One advantage would be to
reduce the number of using declarations a user would need to be able to use
any without boost qualifications.

4. Add a templatized swap that swaps an "any" object for an
arbitrarily-typed object, throwing on type mismatch.

5. Negate the logic of #ifdef COMPILING_MSVC so the conforming-compiler case
is presented first.

6. Drop the using directives from the example in the documentation, and add
"using boost::any; using boost::any_cast;". This will provide a good
example of how code can be very readable without resorting to the
problamatic using directive.


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