Peter Foelsche wrote:
"Alan Tennant"
wrote in message news:a557f5fb1002011639i142be9a0j29205e3ae643a6a9@mail.gmail.com... Thanks :ΒΌ) I can't test it until tomorrow but it looks great. This appears to take boost::any closer to boost::variant.
<< support is most useful. I presume they still cast back to the original object in the same way that boost::any does and any non standard object they contain that will work in a stream will now work inside the boost::any.
Is this going to be an official update or just a branch for me.
I'm still unclear how to work with the people from boost. Usually I'm posting something here and hope for an answer.
Kevlin, who wrote Any and I presume is still the maintainer, is not often seen on the lists so if you want a patch then I suspect Trac items and perhaps direct emails will be necessary.
Can I get a mention for inspiring the idea?
Whats the empty struct for in main?
just for testing what happens if some class does not provide the << operator.
Peter
I only compiled and ran the code in my head but I think it is quite dangerous. Isn't the only reason it compiles is because operator<<(ostream&,any const&) is recursive in the case that the any holds a non-streamable type? E.g. the C in your case. Thus, if the user accidentally tries to stream a non-streamable type he hard-crashes his program by blowing the stack... and because it is an any he has no means of knowing for sure if the contents are streamable at instantiation time. He has to "trust to luck". The OP might not like the term "type-safe" but here the downsides of non-type safety are showing themselves up! Of course a more advanced implementation might go down a has_operator_stream metafunction route. But then you are getting well away from the spirit of Any and towards that of Adobe.Poly as another posted mentioned. Pete