#ifndef BOOST_ANY_INCLUDED
#define BOOST_ANY_INCLUDED
-#if defined(_MSC_VER) && (_MSC_VER >= 1020)
+#if defined(_MSC_VER)
# pragma once
#endif
// when: July 2001, April 2013 - May 2013
#include <algorithm>
-#include <typeinfo>
#include "boost/config.hpp"
+#include <boost/type_index.hpp>
#include <boost/type_traits/remove_reference.hpp>
#include <boost/type_traits/decay.hpp>
+#include <boost/type_traits/remove_cv.hpp>
#include <boost/type_traits/add_reference.hpp>
#include <boost/type_traits/is_reference.hpp>
#include <boost/type_traits/is_const.hpp>
#include <boost/utility/enable_if.hpp>
#include <boost/type_traits/is_same.hpp>
#include <boost/type_traits/is_const.hpp>
-
-// See boost/python/type_id.hpp
-// TODO: add BOOST_TYPEID_COMPARE_BY_NAME to config.hpp
-# if (defined(__GNUC__) && __GNUC__ >= 3) \
- || defined(_AIX) \
- || ( defined(__sgi) && defined(__host_mips)) \
- || (defined(__hpux) && defined(__HP_aCC)) \
- || (defined(linux) && defined(__INTEL_COMPILER) && defined(__ICC))
-# define BOOST_AUX_ANY_TYPE_ID_NAME
-#include <cstring>
-# endif
-
-#if defined(_MSC_VER)
-#pragma warning(push)
-#pragma warning(disable: 4172) // Mistakenly warns: returning address of local variable or temporary
-#endif
+#include <boost/mpl/if.hpp>
namespace boost
{
template<typename ValueType>
any(const ValueType & value)
- : content(new holder<BOOST_DEDUCED_TYPENAME decay<const ValueType>::type>(value))
+ : content(new holder<
+ BOOST_DEDUCED_TYPENAME remove_cv<BOOST_DEDUCED_TYPENAME decay<const ValueType>::type>::type
+ >(value))
{
}
any().swap(*this);
}
- const std::type_info & type() const BOOST_NOEXCEPT
+ const boost::typeindex::type_info& type() const BOOST_NOEXCEPT
{
- return content ? content->type() : typeid(void);
+ return content ? content->type() : boost::typeindex::type_id<void>().type_info();
}
#ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS
public: // queries
- virtual const std::type_info & type() const BOOST_NOEXCEPT = 0;
+ virtual const boost::typeindex::type_info& type() const BOOST_NOEXCEPT = 0;
virtual placeholder * clone() const = 0;
#endif
public: // queries
- virtual const std::type_info & type() const BOOST_NOEXCEPT
+ virtual const boost::typeindex::type_info& type() const BOOST_NOEXCEPT
{
- return typeid(ValueType);
+ return boost::typeindex::type_id<ValueType>().type_info();
}
virtual placeholder * clone() const
lhs.swap(rhs);
}
- class BOOST_SYMBOL_VISIBLE bad_any_cast : public std::bad_cast
+ class BOOST_SYMBOL_VISIBLE bad_any_cast :
+#ifndef BOOST_NO_RTTI
+ public std::bad_cast
+#else
+ public std::exception
+#endif
{
public:
virtual const char * what() const BOOST_NOEXCEPT_OR_NOTHROW
template<typename ValueType>
ValueType * any_cast(any * operand) BOOST_NOEXCEPT
{
- return operand &&
-#ifdef BOOST_AUX_ANY_TYPE_ID_NAME
- std::strcmp(operand->type().name(), typeid(ValueType).name()) == 0
-#else
- operand->type() == typeid(ValueType)
-#endif
- ? &static_cast<any::holder<ValueType> *>(operand->content)->held
+ return operand && operand->type() == boost::typeindex::type_id<ValueType>()
+ ? &static_cast<any::holder<BOOST_DEDUCED_TYPENAME remove_cv<ValueType>::type> *>(operand->content)->held
: 0;
}
{
typedef BOOST_DEDUCED_TYPENAME remove_reference<ValueType>::type nonref;
-#ifdef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
- // If 'nonref' is still reference type, it means the user has not
- // specialized 'remove_reference'.
-
- // Please use BOOST_BROKEN_COMPILER_TYPE_TRAITS_SPECIALIZATION macro
- // to generate specialization of remove_reference for your class
- // See type traits library documentation for details
- BOOST_STATIC_ASSERT(!is_reference<nonref>::value);
-#endif
nonref * result = any_cast<nonref>(&operand);
if(!result)
inline ValueType any_cast(const any & operand)
{
typedef BOOST_DEDUCED_TYPENAME remove_reference<ValueType>::type nonref;
-
-#ifdef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
- // The comment in the above version of 'any_cast' explains when this
- // assert is fired and what to do.
- BOOST_STATIC_ASSERT(!is_reference<nonref>::value);
-#endif
-
return any_cast<const nonref &>(const_cast<any &>(operand));
}
#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
template<typename ValueType>
- inline ValueType&& any_cast(any&& operand)
+ inline ValueType any_cast(any&& operand)
{
BOOST_STATIC_ASSERT_MSG(
- boost::is_rvalue_reference<ValueType&&>::value
+ boost::is_rvalue_reference<ValueType&&>::value /*true if ValueType is rvalue or just a value*/
|| boost::is_const< typename boost::remove_reference<ValueType>::type >::value,
"boost::any_cast shall not be used for getting nonconst references to temporary objects"
);
- return any_cast<ValueType&&>(operand);
+ return any_cast<ValueType>(operand);
}
#endif
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
-#if defined(_MSC_VER)
-#pragma warning(pop)
-#endif
-
#endif