Boost logo

Boost Users :

From: Gernot Vormayr (gernot.vormayr_at_[hidden])
Date: 2007-09-01 11:46:33


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<any::holder<ValueType>
*>(operand->content)->held
                     : 0;
     }

Is there a better way to address this issue?

Best regards,
Gernot Vormayr


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