boost/any.hpp (version 1.55) defines (line 263)
template<typename ValueType>
inline const ValueType * any_cast(const any * operand) BOOST_NOEXCEPT
{
return any_cast<ValueType>(const_cast<any *>(operand));
}
However, using const_cast<>
, may result in undefined behaviour if the original object was not declared const
as in
class foo
{
boost::any value;
template<typename T>
foo(T const&x) noexcept : value(x) {}
template<typename T>
const T*ptr() const noexcept
{ return boost::any_cast(value); }
};
So, is boost kosher?