[boost any] casting problems (BUG?)

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.

On 29/01/2008, Ovanes Markarian <om_boost@keywallet.com> wrote:
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.
The developer of boost::any isn't active on this list nowadays. But here's a post where he explains this, a long discussion followed: http://lists.boost.org/Archives/boost/2004/02/61713.php Daniel
participants (2)
-
Daniel James
-
Ovanes Markarian