Boost logo

Boost Users :

From: Douglas Paul Gregor (gregod_at_[hidden])
Date: 2003-04-04 12:29:37


On Fri, 4 Apr 2003, Electric Monk wrote:
> Can anyone suggest a simple way around this? My own musings on the subject
> have lead me to thinking that there needs to be a simple way to extract the
> contained value, or write it to a stream, without knowing its type.
>
> The simplest method I can see would be to add a function to
> boost::any::placeholder which either returns a string representation of the
> held value or writes the held value to a std::basic_ostream. This should
> allow a simple boost::lexical_cast conversion for boost::any to any
> arbitrary type.
>
> Comments? Have I missed anything major?
>
> Oh, and yes, I know that this goes beyond the intent of boost::any. I could
> easily create my own variant of boost::any which acts in the way I want, but
> I think this kind of functionality is useful in a number of cases, so it'd
> be nice to have the best solution possible... which is best discussed by the
> people here, who are much better versed in the boost library than I :)

Alexander Nasonov is working on dynamic_any, which is a _much_ more
powerful version of boost::any that allows you to include arbitrary
operations. For your situation, you would want something like:

  typedef dynamic_any<output_streamable> my_streamable_any;

It's not an official Boost library, but thus far it is quite impressive.

> The Electric Monk
> "Quidquid latine dictum sit, altum viditur!"

:)

        Doug


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net