Re: [Boost-users] boost any questions and praise
Thanks for the info. Can it be done (at all, at the moment, elegantly,
Alan Tennant wrote: practically, by turning a std::type_info into a type) ? Depending on exactly what you are trying to do, the Boost.Variant library may be more useful than Boost.Any.
Depending on exactly what you are trying to do, the Boost.Variant library may be more useful than Boost.Any.
I suppose it was a "wouldn't it be nifty if it could" not a need. My needs are already met by boost::any and my question was quite precise so I guess your answer is no. I presume you can't pass the .type to on of your own templates either and expect the template to understand it as the type it represents. Variant seems functionally inferior to Any, the big'y being that you need to know all the types in advance.
and std::vector is even more type safe, but even less useful.
I think the term "type safe" having the word "safe" in it was created by
it's supporters, it's as biased as a term as "strongly typed".
If some code is getting an object then that code already knows why it is
requesting that object and what it will do with the object, what methods it
would make sense to call on the object, what methods might not be available
and the such.
If there were no recursive functions, or objects, no flow control like "for"
or "while" available, nothing like a code type either that would allow you
to abstract a loop, then your program would be guaranteed "loop safe" and
"lockup safe".
Maybe there should be a fixed number of types, like in the original C with
no objects, then it would be totally safe.
On 31 January 2010 16:26, Igor R
Variant seems functionally inferior to Any, the big'y being that you need to know all the types in advance.
It's not inferior but superior, as it allows type-safety.
On Sun, Jan 31, 2010 at 10:09 AM, Alan Tennant
and std::vector is even more type safe, but even less useful.
I think the term "type safe" having the word "safe" in it was created by it's supporters, it's as biased as a term as "strongly typed".
If some code is getting an object then that code already knows why it is requesting that object and what it will do with the object, what methods it would make sense to call on the object, what methods might not be available and the such.
If there were no recursive functions, or objects, no flow control like "for" or "while" available, nothing like a code type either that would allow you to abstract a loop, then your program would be guaranteed "loop safe" and "lockup safe".
Maybe there should be a fixed number of types, like in the original C with no objects, then it would be totally safe.
Variant is superior to Any in a few ways: Speed: Variant does a switch lookup, very fast, inlined visitors. Any requires RTTI which has a *VERY* slow lookup, plus a virtual function call. Memory: Variant does not allocate memory unless your variant is recursive, Any tends to allocate memory in general.
What is supposed to go in the <> of the new any_stream (that perhaps should
have a different name)?
On 9 February 2010 18:20, Noah Roberts
In article
, alan2here@gmail.com says... and std::vector is even more type safe, but even less useful.
I think I have to debate your definition of "useful". I use std::vector way, way more often than boost::any.
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (5)
-
Alan Tennant
-
Igor R
-
Noah Roberts
-
OvermindDL1
-
Pete Bartlett