#include #include #include namespace boost { template class any_cast2 : noncopyable { const any & m_any; public: explicit any_cast2( const any & v ) : m_any( v ) {} operator T() const { return any_cast( m_any ); } }; template class any_cast2 : noncopyable { any * const m_any; public: explicit any_cast2( any * v ) : m_any( v ) {} operator T * () const { return any_cast( m_any ); } }; template class any_cast2 : noncopyable { const any * const m_any; public: explicit any_cast2( const any * v ) : m_any( v ) {} operator const T * () const { return any_cast( m_any ); } }; template class any_cast2 : noncopyable { any & m_any; public: explicit any_cast2( any & v ) : m_any( v ) {} operator T & () const { return any_cast( m_any ); } }; template class any_cast2 : noncopyable { const any & m_any; public: explicit any_cast2( const any & v ) : m_any( v ) {} operator const T & () const { return any_cast( m_any ); } }; } int main( int argc, char * argv[] ) { boost::any any1 = argc; // correct try { int i = boost::any_cast2( any1 ); } catch( ... ) { assert( 0 ); } try { const int i = boost::any_cast2( any1 ); } catch( ... ) { assert( 0 ); } try { int * i = boost::any_cast2( &any1 ); } catch( ... ) { assert( 0 ); } try { const int * i = boost::any_cast2( &any1 ); } catch( ... ) { assert( 0 ); } try { int & i = boost::any_cast2( any1 ); } catch( ... ) { assert( 0 ); } try { const int & i = boost::any_cast2( any1 ); } catch( ... ) { assert( 0 ); } return 0; }