Skip to content

Commit

Permalink
Merge 8db591c into 6b4e6fe
Browse files Browse the repository at this point in the history
  • Loading branch information
apolukhin committed Apr 10, 2021
2 parents 6b4e6fe + 8db591c commit 3dc577f
Show file tree
Hide file tree
Showing 36 changed files with 1,870 additions and 717 deletions.
49 changes: 26 additions & 23 deletions include/boost/any.hpp
Expand Up @@ -3,18 +3,20 @@
#ifndef BOOST_ANY_INCLUDED
#define BOOST_ANY_INCLUDED

#if defined(_MSC_VER)
#include <boost/config.hpp>
#ifdef BOOST_HAS_PRAGMA_ONCE
# pragma once
#endif

// what: variant type boost::any
// who: contributed by Kevlin Henney,
// with features contributed and bugs found by
// Antony Polukhin, Ed Brey, Mark Rodgers,
// Antony Polukhin, Ed Brey, Mark Rodgers,
// Peter Dimov, and James Curran
// when: July 2001, April 2013 - 2020

#include <boost/config.hpp>
#include <boost/anys/bad_any_cast.hpp>
#include <boost/anys/fwd.hpp>
#include <boost/type_index.hpp>
#include <boost/type_traits/remove_reference.hpp>
#include <boost/type_traits/decay.hpp>
Expand Down Expand Up @@ -47,6 +49,10 @@ namespace boost
BOOST_DEDUCED_TYPENAME remove_cv<BOOST_DEDUCED_TYPENAME decay<const ValueType>::type>::type
>(value))
{
BOOST_STATIC_ASSERT_MSG(
!anys::detail::is_basic_any<ValueType>::value,
"boost::any shall not be constructed from boost::anys::basic_any"
);
}

any(const any & other)
Expand All @@ -69,6 +75,10 @@ namespace boost
, typename boost::disable_if<boost::is_const<ValueType> >::type* = 0) // disable if value has type `const ValueType&&`
: content(new holder< typename decay<ValueType>::type >(static_cast<ValueType&&>(value)))
{
BOOST_STATIC_ASSERT_MSG(
!anys::detail::is_basic_any<typename boost::decay<ValueType>::type>::value,
"boost::any shall not be constructed from boost::anys::basic_any"
);
}
#endif

Expand All @@ -92,6 +102,10 @@ namespace boost
template<typename ValueType>
any & operator=(const ValueType & rhs)
{
BOOST_STATIC_ASSERT_MSG(
!anys::detail::is_basic_any<ValueType>::value,
"boost::anys::basic_any shall not be assigned into boost::any"
);
any(rhs).swap(*this);
return *this;
}
Expand All @@ -102,7 +116,7 @@ namespace boost
return *this;
}

#else
#else
any & operator=(const any& rhs)
{
any(rhs).swap(*this);
Expand All @@ -121,6 +135,10 @@ namespace boost
template <class ValueType>
any & operator=(ValueType&& rhs)
{
BOOST_STATIC_ASSERT_MSG(
!anys::detail::is_basic_any<typename boost::decay<ValueType>::type>::value,
"boost::anys::basic_any shall not be assigned into boost::any"
);
any(static_cast<ValueType&&>(rhs)).swap(*this);
return *this;
}
Expand Down Expand Up @@ -224,27 +242,12 @@ namespace boost
placeholder * content;

};

inline void swap(any & lhs, any & rhs) BOOST_NOEXCEPT
{
lhs.swap(rhs);
}

class BOOST_SYMBOL_VISIBLE bad_any_cast :
#ifndef BOOST_NO_RTTI
public std::bad_cast
#else
public std::exception
#endif
{
public:
const char * what() const BOOST_NOEXCEPT_OR_NOTHROW BOOST_OVERRIDE
{
return "boost::bad_any_cast: "
"failed conversion using boost::any_cast";
}
};

template<typename ValueType>
ValueType * any_cast(any * operand) BOOST_NOEXCEPT
{
Expand All @@ -271,9 +274,9 @@ namespace boost
if(!result)
boost::throw_exception(bad_any_cast());

// Attempt to avoid construction of a temporary object in cases when
// Attempt to avoid construction of a temporary object in cases when
// `ValueType` is not a reference. Example:
// `static_cast<std::string>(*result);`
// `static_cast<std::string>(*result);`
// which is equal to `std::string(*result);`
typedef BOOST_DEDUCED_TYPENAME boost::conditional<
boost::is_reference<ValueType>::value,
Expand Down Expand Up @@ -305,7 +308,7 @@ namespace boost
BOOST_STATIC_ASSERT_MSG(
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"
"boost::any_cast shall not be used for getting nonconst references to temporary objects"
);
return any_cast<ValueType>(operand);
}
Expand Down
40 changes: 40 additions & 0 deletions include/boost/anys/bad_any_cast.hpp
@@ -0,0 +1,40 @@
// Copyright Antony Polukhin, 2020-2021.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)

// See http://www.boost.org/libs/any for Documentation.

#ifndef BOOST_ANYS_UNIQUE_ANY_INCLUDED
#define BOOST_ANYS_UNIQUE_ANY_INCLUDED

#include <boost/config.hpp>
#ifdef BOOST_HAS_PRAGMA_ONCE
# pragma once
#endif

#include <boost/type_index.hpp>


namespace boost {

class BOOST_SYMBOL_VISIBLE bad_any_cast :
#ifndef BOOST_NO_RTTI
public std::bad_cast
#else
public std::exception
#endif
{
public:
const char * what() const BOOST_NOEXCEPT_OR_NOTHROW BOOST_OVERRIDE
{
return "boost::bad_any_cast: "
"failed conversion using boost::any_cast";
}
};

} // namespace boost


#endif // BOOST_ANYS_UNIQUE_ANY_INCLUDED

0 comments on commit 3dc577f

Please sign in to comment.