Boost logo

Boost Users :

From: Ovanes Markarian (om_boost_at_[hidden])
Date: 2008-01-29 12:28:22


Hello *,

I would like to ask the developers of boost::any if the ctor template in
boost::any

        template<typename ValueType>
        any(const ValueType & value)
          : content(new holder<ValueType>(value))
        {
        }

is intentionally not marked as explicit. Today using boost::any_cast and
with a std::map (mapping of some id to boost::any) iterator I was wondering
why I got an exception when I found a correct any instance.

My code looked like:

map_type::const_iterator iter = map.find(Key);
if(map.end()!=iter)
   return boost::any_cast<SomeResultType const&>(*iter);

Unforturenately, I forgot that map iterator references a pair<KeyType,
ValueType>. This cast caused the compiler to implicitly create a new const
any type containing the dereferenced pair and throw an exception that my
expected result type was wrong. I don't know which design rationale was
intended when this ctor was not marked as explicit or if it is a bug.

With Kind Regards,
Ovanes

BTW, I use boost 1.34.1 and vc 7.1.



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