boost::any typeid and different modules
Hi!
I have some problems using boost::any in different modules that get
loaded with libdl. If i store an int in the boost::any it works like a
charm - but when i use a std::string then the boost::any (holding a
std::string) isn't any_castable to a std::string because it seems that
typeid(std::string) != boost::any.type(). Only thing which is the same
is the string represantation of type().name().
I came around this with my own any_cast implementation:
template<typename ValueType>
ValueType * any_cast(any * operand)
{
return operand &&
(operand->type() == typeid(ValueType) ||
std::string(operand->type().name()).compare(typeid(ValueType).name())==0)
? &static_cast
Hi Gernot,
On 9/1/07, Gernot Vormayr
Hi!
I have some problems using boost::any in different modules that get loaded with libdl. If i store an int in the boost::any it works like a charm - but when i use a std::string then the boost::any (holding a std::string) isn't any_castable to a std::string because it seems that typeid(std::string) != boost::any.type(). Only thing which is the same is the string represantation of type().name().
I've recently encountered this issue, too. The comparison failes because it compares pointers and each module has its own static rtti information. You could try http://lists.boost.org/Archives/boost/2007/07/124502.php for a solution. HTH, Stephan
Thank you for the link. This was just what I was looking for. After reading the thread (and a thread which was linked by this one) I hope to fully understand what is going on. Well -rdynamic didn't work for me, cause I'm developing on mac os x, but after removing -fvisibility=hidden it started working. thx, Gernot Stephan Diederich schrieb:
Hi Gernot,
On 9/1/07, *Gernot Vormayr*
mailto:gernot.vormayr@student.tuwien.ac.at> wrote: Hi!
I have some problems using boost::any in different modules that get loaded with libdl. If i store an int in the boost::any it works like a charm - but when i use a std::string then the boost::any (holding a std::string) isn't any_castable to a std::string because it seems that typeid(std::string) != boost::any.type(). Only thing which is the same is the string represantation of type().name().
I've recently encountered this issue, too. The comparison failes because it compares pointers and each module has its own static rtti information. You could try http://lists.boost.org/Archives/boost/2007/07/124502.php for a solution.
HTH, Stephan
------------------------------------------------------------------------
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (2)
-
Gernot Vormayr
-
Stephan Diederich