diff --git a/CMakeLists.txt b/CMakeLists.txt index 1e383a1..792cece 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,9 +13,6 @@ target_include_directories( boost_any INTERFACE include ) target_link_libraries( boost_any INTERFACE Boost::config - Boost::core - Boost::static_assert Boost::throw_exception Boost::type_index - Boost::type_traits ) diff --git a/include/boost/any.hpp b/include/boost/any.hpp index 1500964..f7812ee 100644 --- a/include/boost/any.hpp +++ b/include/boost/any.hpp @@ -21,19 +21,11 @@ #include #include #include -#include -#include -#include -#include -#include -#include -#include #include -#include -#include -#include -#include -#include +#include + +#include // for std::addressof +#include namespace boost { @@ -44,7 +36,7 @@ namespace boost public: /// \post this->empty() is true. - BOOST_CONSTEXPR any() BOOST_NOEXCEPT + constexpr any() noexcept : content(0) { } @@ -58,10 +50,10 @@ namespace boost template any(const ValueType & value) : content(new holder< - BOOST_DEDUCED_TYPENAME remove_cv::type>::type + typename std::remove_cv::type>::type >(value)) { - BOOST_STATIC_ASSERT_MSG( + static_assert( !anys::detail::is_basic_any::value, "boost::any shall not be constructed from boost::anys::basic_any" ); @@ -80,14 +72,12 @@ namespace boost { } -#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES /// Move constructor that moves content of /// `other` into new instance and leaves `other` empty. /// - /// \pre C++11 compatible compiler /// \post other->empty() is true /// \throws Nothing. - any(any&& other) BOOST_NOEXCEPT + any(any&& other) noexcept : content(other.content) { other.content = 0; @@ -97,26 +87,24 @@ namespace boost /// that the initial content of the new instance is equivalent /// in both type and value to `value` before the forward. /// - /// \pre C++11 compatible compiler. /// \throws std::bad_alloc or any exceptions arising from the move or /// copy constructor of the contained type. template any(ValueType&& value - , typename boost::disable_if >::type* = 0 // disable if value has type `any&` - , typename boost::disable_if >::type* = 0) // disable if value has type `const ValueType&&` - : content(new holder< typename decay::type >(static_cast(value))) + , typename std::enable_if::value >::type* = 0 // disable if value has type `any&` + , typename std::enable_if::value >::type* = 0) // disable if value has type `const ValueType&&` + : content(new holder< typename std::decay::type >(std::forward(value))) { - BOOST_STATIC_ASSERT_MSG( - !anys::detail::is_basic_any::type>::value, + static_assert( + !anys::detail::is_basic_any::type>::value, "boost::any shall not be constructed from boost::anys::basic_any" ); } -#endif /// Releases any and all resources used in management of instance. /// /// \throws Nothing. - ~any() BOOST_NOEXCEPT + ~any() noexcept { delete content; } @@ -127,7 +115,7 @@ namespace boost /// /// \returns `*this` /// \throws Nothing. - any & swap(any & rhs) BOOST_NOEXCEPT + any & swap(any & rhs) noexcept { placeholder* tmp = content; content = rhs.content; @@ -150,37 +138,15 @@ namespace boost return *this; } -#ifdef BOOST_NO_CXX11_RVALUE_REFERENCES - /// Makes a copy of `rhs`, - /// discarding previous content, so that the new content of is - /// equivalent in both type and value to - /// `rhs`. - /// - /// \throws std::bad_alloc - /// or any exceptions arising from the copy constructor of the - /// contained type. Assignment satisfies the strong guarantee - /// of exception safety. - template - any & operator=(const ValueType & rhs) - { - BOOST_STATIC_ASSERT_MSG( - !anys::detail::is_basic_any::value, - "boost::anys::basic_any shall not be assigned into boost::any" - ); - any(rhs).swap(*this); - return *this; - } -#else /// Moves content of `rhs` into /// current instance, discarding previous content, so that the /// new content is equivalent in both type and value to the /// content of `rhs` before move, or empty if /// `rhs.empty()`. /// - /// \pre C++11 compatible compiler. /// \post `rhs->empty()` is true /// \throws Nothing. - any & operator=(any&& rhs) BOOST_NOEXCEPT + any & operator=(any&& rhs) noexcept { rhs.swap(*this); any().swap(rhs); @@ -192,7 +158,6 @@ namespace boost /// equivalent in both type and value to /// `rhs` before forward. /// - /// \pre C++11 compatible compiler. /// \throws std::bad_alloc /// or any exceptions arising from the move or copy constructor of the /// contained type. Assignment satisfies the strong guarantee @@ -200,26 +165,25 @@ namespace boost template any & operator=(ValueType&& rhs) { - BOOST_STATIC_ASSERT_MSG( - !anys::detail::is_basic_any::type>::value, + static_assert( + !anys::detail::is_basic_any::type>::value, "boost::anys::basic_any shall not be assigned into boost::any" ); - any(static_cast(rhs)).swap(*this); + any(std::forward(rhs)).swap(*this); return *this; } -#endif public: // queries /// \returns `true` if instance is empty, otherwise `false`. /// \throws Nothing. - bool empty() const BOOST_NOEXCEPT + bool empty() const noexcept { return !content; } /// \post this->empty() is true - void clear() BOOST_NOEXCEPT + void clear() noexcept { any().swap(*this); } @@ -230,16 +194,12 @@ namespace boost /// /// Useful for querying against types known either at compile time or /// only at runtime. - const boost::typeindex::type_info& type() const BOOST_NOEXCEPT + const boost::typeindex::type_info& type() const noexcept { return content ? content->type() : boost::typeindex::type_id().type_info(); } -#ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS private: // types -#else - public: // types (public so any_cast can be non-friend) -#endif /// @cond class BOOST_SYMBOL_VISIBLE placeholder: public boost::anys::detail::placeholder { @@ -248,10 +208,7 @@ namespace boost }; template - class holder -#ifndef BOOST_NO_CXX11_FINAL - final -#endif + class holder final : public placeholder { public: // structors @@ -261,15 +218,14 @@ namespace boost { } -#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES holder(ValueType&& value) : held(static_cast< ValueType&& >(value)) { } -#endif + public: // queries - const boost::typeindex::type_info& type() const BOOST_NOEXCEPT BOOST_OVERRIDE + const boost::typeindex::type_info& type() const noexcept override { return boost::typeindex::type_id().type_info(); } @@ -287,27 +243,19 @@ namespace boost holder & operator=(const holder &); }; -#ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS - private: // representation template - friend ValueType * unsafe_any_cast(any *) BOOST_NOEXCEPT; + friend ValueType * unsafe_any_cast(any *) noexcept; friend class boost::anys::unique_any; -#else - - public: // representation (public so any_cast can be non-friend) - -#endif - placeholder * content; /// @endcond }; /// Exchange of the contents of `lhs` and `rhs`. /// \throws Nothing. - inline void swap(any & lhs, any & rhs) BOOST_NOEXCEPT + inline void swap(any & lhs, any & rhs) noexcept { lhs.swap(rhs); } @@ -320,15 +268,15 @@ namespace boost // use typeid() comparison, e.g., when our types may travel across // different shared libraries. template - inline ValueType * unsafe_any_cast(any * operand) BOOST_NOEXCEPT + inline ValueType * unsafe_any_cast(any * operand) noexcept { - return boost::addressof( + return std::addressof( static_cast *>(operand->content)->held ); } template - inline const ValueType * unsafe_any_cast(const any * operand) BOOST_NOEXCEPT + inline const ValueType * unsafe_any_cast(const any * operand) noexcept { return boost::unsafe_any_cast(const_cast(operand)); } @@ -337,17 +285,17 @@ namespace boost /// \returns Pointer to a ValueType stored in `operand`, nullptr if /// `operand` does not contain specified `ValueType`. template - ValueType * any_cast(any * operand) BOOST_NOEXCEPT + ValueType * any_cast(any * operand) noexcept { return operand && operand->type() == boost::typeindex::type_id() - ? boost::unsafe_any_cast::type>(operand) + ? boost::unsafe_any_cast::type>(operand) : 0; } /// \returns Const pointer to a ValueType stored in `operand`, nullptr if /// `operand` does not contain specified `ValueType`. template - inline const ValueType * any_cast(const any * operand) BOOST_NOEXCEPT + inline const ValueType * any_cast(const any * operand) noexcept { return boost::any_cast(const_cast(operand)); } @@ -358,9 +306,9 @@ namespace boost template ValueType any_cast(any & operand) { - typedef BOOST_DEDUCED_TYPENAME remove_reference::type nonref; + typedef typename std::remove_reference::type nonref; - nonref * result = boost::any_cast(boost::addressof(operand)); + nonref * result = boost::any_cast(std::addressof(operand)); if(!result) boost::throw_exception(bad_any_cast()); @@ -368,10 +316,10 @@ namespace boost // `ValueType` is not a reference. Example: // `static_cast(*result);` // which is equal to `std::string(*result);` - typedef BOOST_DEDUCED_TYPENAME boost::conditional< - boost::is_reference::value, + typedef typename std::conditional< + std::is_reference::value, ValueType, - BOOST_DEDUCED_TYPENAME boost::add_reference::type + typename std::add_lvalue_reference::type >::type ref_type; #ifdef BOOST_MSVC @@ -390,25 +338,23 @@ namespace boost template inline ValueType any_cast(const any & operand) { - typedef BOOST_DEDUCED_TYPENAME remove_reference::type nonref; + typedef typename std::remove_reference::type nonref; return boost::any_cast(const_cast(operand)); } -#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES /// \returns `ValueType` stored in `operand`, leaving the `operand` empty. /// \throws boost::bad_any_cast if `operand` does not contain /// specified `ValueType`. template inline ValueType any_cast(any&& operand) { - BOOST_STATIC_ASSERT_MSG( - boost::is_rvalue_reference::value /*true if ValueType is rvalue or just a value*/ - || boost::is_const< typename boost::remove_reference::type >::value, + static_assert( + std::is_rvalue_reference::value /*true if ValueType is rvalue or just a value*/ + || std::is_const< typename std::remove_reference::type >::value, "boost::any_cast shall not be used for getting nonconst references to temporary objects" ); return boost::any_cast(operand); } -#endif } // Copyright Kevlin Henney, 2000, 2001, 2002. All rights reserved. diff --git a/include/boost/any/bad_any_cast.hpp b/include/boost/any/bad_any_cast.hpp index e715938..ed45602 100644 --- a/include/boost/any/bad_any_cast.hpp +++ b/include/boost/any/bad_any_cast.hpp @@ -32,7 +32,7 @@ class BOOST_SYMBOL_VISIBLE bad_any_cast : #endif { public: - const char * what() const BOOST_NOEXCEPT_OR_NOTHROW BOOST_OVERRIDE + const char * what() const BOOST_NOEXCEPT_OR_NOTHROW override { return "boost::bad_any_cast: " "failed conversion using boost::any_cast"; diff --git a/include/boost/any/basic_any.hpp b/include/boost/any/basic_any.hpp index 6e7665e..116cb4e 100644 --- a/include/boost/any/basic_any.hpp +++ b/include/boost/any/basic_any.hpp @@ -21,21 +21,12 @@ #include #include #include -#include #include -#include -#include -#include -#include -#include -#include -#include #include -#include -#include -#include -#include -#include + +#include // for std::addressof +#include + namespace boost { @@ -63,10 +54,10 @@ namespace anys { template class basic_any { - BOOST_STATIC_ASSERT_MSG(OptimizeForSize > 0 && OptimizeForAlignment > 0, "Size and Align shall be positive values"); - BOOST_STATIC_ASSERT_MSG(OptimizeForSize >= OptimizeForAlignment, "Size shall non less than Align"); - BOOST_STATIC_ASSERT_MSG((OptimizeForAlignment & (OptimizeForAlignment - 1)) == 0, "Align shall be a power of 2"); - BOOST_STATIC_ASSERT_MSG(OptimizeForSize % OptimizeForAlignment == 0, "Size shall be multiple of alignment"); + static_assert(OptimizeForSize > 0 && OptimizeForAlignment > 0, "Size and Align shall be positive values"); + static_assert(OptimizeForSize >= OptimizeForAlignment, "Size shall non less than Align"); + static_assert((OptimizeForAlignment & (OptimizeForAlignment - 1)) == 0, "Align shall be a power of 2"); + static_assert(OptimizeForSize % OptimizeForAlignment == 0, "Size shall be multiple of alignment"); private: /// @cond enum operation @@ -94,11 +85,7 @@ namespace anys { BOOST_ASSERT(!right->empty()); BOOST_ASSERT(right->type() == boost::typeindex::type_id()); ValueType* value = reinterpret_cast(&const_cast(right)->content.small_value); -#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES new (&left.content.small_value) ValueType(std::move(*value)); -#else - new (&left.content.small_value) ValueType(*value); -#endif left.man = right->man; reinterpret_cast(&right->content.small_value)->~ValueType(); const_cast(right)->man = 0; @@ -118,10 +105,10 @@ namespace anys { BOOST_ASSERT(info); BOOST_ASSERT(!left.empty()); return boost::typeindex::type_id() == *info ? - reinterpret_cast::type *>(&left.content.small_value) : 0; + reinterpret_cast::type *>(&left.content.small_value) : 0; case UnsafeCast: BOOST_ASSERT(!left.empty()); - return reinterpret_cast::type *>(&left.content.small_value); + return reinterpret_cast::type *>(&left.content.small_value); case Typeinfo: return const_cast(static_cast(&boost::typeindex::type_id().type_info())); } @@ -160,10 +147,10 @@ namespace anys { BOOST_ASSERT(info); BOOST_ASSERT(!left.empty()); return boost::typeindex::type_id() == *info ? - static_cast::type *>(left.content.large_value) : 0; + static_cast::type *>(left.content.large_value) : 0; case UnsafeCast: BOOST_ASSERT(!left.empty()); - return reinterpret_cast::type *>(left.content.large_value); + return reinterpret_cast::type *>(left.content.large_value); case Typeinfo: return const_cast(static_cast(&boost::typeindex::type_id().type_info())); } @@ -172,56 +159,54 @@ namespace anys { } template - struct is_small_object : boost::integral_constant::value <= OptimizeForAlignment && - boost::is_nothrow_move_constructible::value> + struct is_small_object : std::integral_constant::value> {}; template - static void create(basic_any& any, const ValueType& value, boost::true_type) + static void create(basic_any& any, const ValueType& value, std::true_type) { - typedef typename boost::decay::type DecayedType; + typedef typename std::decay::type DecayedType; any.man = &small_manager; new (&any.content.small_value) ValueType(value); } template - static void create(basic_any& any, const ValueType& value, boost::false_type) + static void create(basic_any& any, const ValueType& value, std::false_type) { - typedef typename boost::decay::type DecayedType; + typedef typename std::decay::type DecayedType; any.man = &large_manager; any.content.large_value = new DecayedType(value); } -#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES template - static void create(basic_any& any, ValueType&& value, boost::true_type) + static void create(basic_any& any, ValueType&& value, std::true_type) { - typedef typename boost::decay::type DecayedType; + typedef typename std::decay::type DecayedType; any.man = &small_manager; - new (&any.content.small_value) DecayedType(static_cast(value)); + new (&any.content.small_value) DecayedType(std::forward(value)); } template - static void create(basic_any& any, ValueType&& value, boost::false_type) + static void create(basic_any& any, ValueType&& value, std::false_type) { - typedef typename boost::decay::type DecayedType; + typedef typename std::decay::type DecayedType; any.man = &large_manager; - any.content.large_value = new DecayedType(static_cast(value)); + any.content.large_value = new DecayedType(std::forward(value)); } -#endif /// @endcond public: // non-type template parameters accessors - static BOOST_CONSTEXPR_OR_CONST std::size_t buffer_size = OptimizeForSize; - static BOOST_CONSTEXPR_OR_CONST std::size_t buffer_align = OptimizeForAlignment; + static constexpr std::size_t buffer_size = OptimizeForSize; + static constexpr std::size_t buffer_align = OptimizeForAlignment; public: // structors /// \post this->empty() is true. - BOOST_CONSTEXPR basic_any() BOOST_NOEXCEPT + constexpr basic_any() noexcept : man(0), content() { } @@ -240,11 +225,11 @@ namespace anys { basic_any(const ValueType & value) : man(0), content() { - BOOST_STATIC_ASSERT_MSG( - !(boost::is_same::value), + static_assert( + !std::is_same::value, "boost::anys::basic_any shall not be constructed from boost::any" ); - BOOST_STATIC_ASSERT_MSG( + static_assert( !anys::detail::is_basic_any::value, "boost::anys::basic_any shall not be constructed from boost::anys::basic_any" ); @@ -268,14 +253,12 @@ namespace anys { } } -#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES /// Move constructor that moves content of /// `other` into new instance and leaves `other` empty. /// - /// \pre C++11 compatible compiler /// \post other->empty() is true /// \throws Nothing. - basic_any(basic_any&& other) BOOST_NOEXCEPT + basic_any(basic_any&& other) noexcept : man(0), content() { if (other.man) @@ -292,32 +275,30 @@ namespace anys { /// move constructible and `sizeof(value) <= OptimizeForSize` and /// `alignof(value) <= OptimizeForAlignment`. /// - /// \pre C++11 compatible compiler. /// \throws std::bad_alloc or any exceptions arising from the move or /// copy constructor of the contained type. template basic_any(ValueType&& value - , typename boost::disable_if >::type* = 0 // disable if value has type `basic_any&` - , typename boost::disable_if >::type* = 0) // disable if value has type `const ValueType&&` + , typename std::enable_if::value >::type* = 0 // disable if value has type `basic_any&` + , typename std::enable_if::value >::type* = 0) // disable if value has type `const ValueType&&` : man(0), content() { - typedef typename boost::decay::type DecayedType; - BOOST_STATIC_ASSERT_MSG( - !(boost::is_same::value), + typedef typename std::decay::type DecayedType; + static_assert( + !std::is_same::value, "boost::anys::basic_any shall not be constructed from boost::any" ); - BOOST_STATIC_ASSERT_MSG( + static_assert( !anys::detail::is_basic_any::value, "boost::anys::basic_any shall not be constructed from boost::anys::basic_any" ); create(*this, static_cast(value), is_small_object()); } -#endif /// Releases any and all resources used in management of instance. /// /// \throws Nothing. - ~basic_any() BOOST_NOEXCEPT + ~basic_any() noexcept { if (man) { @@ -331,7 +312,7 @@ namespace anys { /// /// \returns `*this` /// \throws Nothing. - basic_any & swap(basic_any & rhs) BOOST_NOEXCEPT + basic_any & swap(basic_any & rhs) noexcept { if (this == &rhs) { @@ -371,47 +352,15 @@ namespace anys { return *this; } - -#ifdef BOOST_NO_CXX11_RVALUE_REFERENCES - /// Makes a copy of `rhs`, - /// discarding previous content, so that the new content of is - /// equivalent in both type and value to - /// `rhs`. - /// - /// Does not dynamically allocate if `ValueType` is nothrow - /// move constructible and `sizeof(value) <= OptimizeForSize` and - /// `alignof(value) <= OptimizeForAlignment`. - /// - /// \throws std::bad_alloc - /// or any exceptions arising from the copy constructor of the - /// contained type. Assignment satisfies the strong guarantee - /// of exception safety. - template - basic_any & operator=(const ValueType & rhs) - { - BOOST_STATIC_ASSERT_MSG( - !(boost::is_same::value), - "boost::any shall not be assigned into boost::anys::basic_any" - ); - BOOST_STATIC_ASSERT_MSG( - !anys::detail::is_basic_any::value, - "boost::anys::basic_any shall not be assigned into boost::anys::basic_any" - ); - basic_any(rhs).swap(*this); - return *this; - } - -#else /// Moves content of `rhs` into /// current instance, discarding previous content, so that the /// new content is equivalent in both type and value to the /// content of `rhs` before move, or empty if /// `rhs.empty()`. /// - /// \pre C++11 compatible compiler. /// \post `rhs->empty()` is true /// \throws Nothing. - basic_any & operator=(basic_any&& rhs) BOOST_NOEXCEPT + basic_any & operator=(basic_any&& rhs) noexcept { rhs.swap(*this); basic_any().swap(rhs); @@ -427,7 +376,6 @@ namespace anys { /// move constructible and `sizeof(value) <= OptimizeForSize` and /// `alignof(value) <= OptimizeForAlignment`. /// - /// \pre C++11 compatible compiler. /// \throws std::bad_alloc /// or any exceptions arising from the move or copy constructor of the /// contained type. Assignment satisfies the strong guarantee @@ -435,31 +383,30 @@ namespace anys { template basic_any & operator=(ValueType&& rhs) { - typedef typename boost::decay::type DecayedType; - BOOST_STATIC_ASSERT_MSG( - !(boost::is_same::value), + typedef typename std::decay::type DecayedType; + static_assert( + !std::is_same::value, "boost::any shall not be assigned into boost::anys::basic_any" ); - BOOST_STATIC_ASSERT_MSG( - (!anys::detail::is_basic_any::value || boost::is_same::value), + static_assert( + !anys::detail::is_basic_any::value || std::is_same::value, "boost::anys::basic_any shall not be assigned into boost::anys::basic_any" ); - basic_any(static_cast(rhs)).swap(*this); + basic_any(std::forward(rhs)).swap(*this); return *this; } -#endif public: // queries /// \returns `true` if instance is empty, otherwise `false`. /// \throws Nothing. - bool empty() const BOOST_NOEXCEPT + bool empty() const noexcept { return !man; } /// \post this->empty() is true - void clear() BOOST_NOEXCEPT + void clear() noexcept { basic_any().swap(*this); } @@ -480,10 +427,10 @@ namespace anys { private: // representation /// @cond template - friend ValueType * any_cast(basic_any *) BOOST_NOEXCEPT; + friend ValueType * any_cast(basic_any *) noexcept; template - friend ValueType * unsafe_any_cast(basic_any *) BOOST_NOEXCEPT; + friend ValueType * unsafe_any_cast(basic_any *) noexcept; typedef void*(*manager)(operation op, basic_any& left, const basic_any* right, const boost::typeindex::type_info* info); @@ -491,7 +438,7 @@ namespace anys { union content { void * large_value; - typename boost::aligned_storage::type small_value; + alignas(OptimizeForAlignment) unsigned char small_value[OptimizeForSize]; } content; /// @endcond }; @@ -499,7 +446,7 @@ namespace anys { /// Exchange of the contents of `lhs` and `rhs`. /// \throws Nothing. template - void swap(basic_any& lhs, basic_any& rhs) BOOST_NOEXCEPT + void swap(basic_any& lhs, basic_any& rhs) noexcept { lhs.swap(rhs); } @@ -507,17 +454,17 @@ namespace anys { /// \returns Pointer to a ValueType stored in `operand`, nullptr if /// `operand` does not contain specified `ValueType`. template - ValueType * any_cast(basic_any * operand) BOOST_NOEXCEPT + ValueType * any_cast(basic_any * operand) noexcept { return operand->man ? - static_cast::type *>(operand->man(basic_any::AnyCast, *operand, 0, &boost::typeindex::type_id().type_info())) + static_cast::type *>(operand->man(basic_any::AnyCast, *operand, 0, &boost::typeindex::type_id().type_info())) : 0; } /// \returns Const pointer to a ValueType stored in `operand`, nullptr if /// `operand` does not contain specified `ValueType`. template - inline const ValueType * any_cast(const basic_any * operand) BOOST_NOEXCEPT + inline const ValueType * any_cast(const basic_any * operand) noexcept { return boost::anys::any_cast(const_cast *>(operand)); } @@ -528,9 +475,9 @@ namespace anys { template ValueType any_cast(basic_any & operand) { - typedef typename remove_reference::type nonref; + typedef typename std::remove_reference::type nonref; - nonref * result = boost::anys::any_cast(boost::addressof(operand)); + nonref * result = boost::anys::any_cast(std::addressof(operand)); if(!result) boost::throw_exception(bad_any_cast()); @@ -538,10 +485,10 @@ namespace anys { // `ValueType` is not a reference. Example: // `static_cast(*result);` // which is equal to `std::string(*result);` - typedef typename boost::conditional< - boost::is_reference::value, + typedef typename std::conditional< + std::is_reference::value, ValueType, - typename boost::add_reference::type + typename std::add_lvalue_reference::type >::type ref_type; #ifdef BOOST_MSVC @@ -560,25 +507,23 @@ namespace anys { template inline ValueType any_cast(const basic_any & operand) { - typedef typename remove_reference::type nonref; + typedef typename std::remove_reference::type nonref; return boost::anys::any_cast(const_cast &>(operand)); } -#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES /// \returns `ValueType` stored in `operand`, leaving the `operand` empty. /// \throws boost::bad_any_cast if `operand` does not contain /// specified `ValueType`. template inline ValueType any_cast(basic_any&& operand) { - BOOST_STATIC_ASSERT_MSG( - boost::is_rvalue_reference::value /*true if ValueType is rvalue or just a value*/ - || boost::is_const< typename boost::remove_reference::type >::value, + static_assert( + std::is_rvalue_reference::value /*true if ValueType is rvalue or just a value*/ + || std::is_const< typename std::remove_reference::type >::value, "boost::any_cast shall not be used for getting nonconst references to temporary objects" ); return boost::anys::any_cast(operand); } -#endif /// @cond @@ -589,13 +534,13 @@ namespace anys { // use typeid() comparison, e.g., when our types may travel across // different shared libraries. template - inline ValueType * unsafe_any_cast(basic_any * operand) BOOST_NOEXCEPT + inline ValueType * unsafe_any_cast(basic_any * operand) noexcept { return static_cast(operand->man(basic_any::UnsafeCast, *operand, 0, 0)); } template - inline const ValueType * unsafe_any_cast(const basic_any * operand) BOOST_NOEXCEPT + inline const ValueType * unsafe_any_cast(const basic_any * operand) noexcept { return boost::anys::unsafe_any_cast(const_cast *>(operand)); } diff --git a/include/boost/any/detail/placeholder.hpp b/include/boost/any/detail/placeholder.hpp index df5db65..360d78c 100644 --- a/include/boost/any/detail/placeholder.hpp +++ b/include/boost/any/detail/placeholder.hpp @@ -22,7 +22,7 @@ namespace detail { class BOOST_SYMBOL_VISIBLE placeholder { public: virtual ~placeholder() {} - virtual const boost::typeindex::type_info& type() const BOOST_NOEXCEPT = 0; + virtual const boost::typeindex::type_info& type() const noexcept = 0; }; } // namespace detail diff --git a/include/boost/any/fwd.hpp b/include/boost/any/fwd.hpp index 21c5bc9..752f3ac 100644 --- a/include/boost/any/fwd.hpp +++ b/include/boost/any/fwd.hpp @@ -16,27 +16,6 @@ /// \file boost/any/fwd.hpp /// \brief Forward declarations of Boost.Any library types. - -#include -#if defined(BOOST_NO_CXX11_RVALUE_REFERENCES) || \ - defined(BOOST_NO_CXX11_AUTO_DECLARATIONS) || \ - defined(BOOST_NO_CXX11_CONSTEXPR) || \ - defined(BOOST_NO_CXX11_NULLPTR) || \ - defined(BOOST_NO_CXX11_NOEXCEPT) || \ - defined(BOOST_NO_CXX11_DEFAULTED_FUNCTIONS) || \ - defined(BOOST_NO_CXX11_FINAL) || \ - defined(BOOST_NO_CXX11_ALIGNOF) || \ - defined(BOOST_NO_CXX11_STATIC_ASSERT) || \ - defined(BOOST_NO_CXX11_SMART_PTR) || \ - defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) || \ - defined(BOOST_NO_CXX11_HDR_TYPE_TRAITS) - -BOOST_PRAGMA_MESSAGE("C++03 support is deprecated in Boost.Any 1.82 and will be removed in Boost.Any 1.84.") - -#endif - -#include - /// @cond namespace boost { @@ -46,25 +25,25 @@ namespace anys { class unique_any; -template::value> +template class basic_any; namespace detail { template - struct is_basic_any: public boost::false_type {}; + struct is_basic_any: public std::false_type {}; template - struct is_basic_any > : public boost::true_type {}; + struct is_basic_any > : public std::true_type {}; template struct is_some_any: public is_basic_any {}; template <> - struct is_some_any: public boost::true_type {}; + struct is_some_any: public std::true_type {}; template <> - struct is_some_any: public boost::true_type {}; + struct is_some_any: public std::true_type {}; } // namespace detail diff --git a/include/boost/any/unique_any.hpp b/include/boost/any/unique_any.hpp index 5b11850..9f4f41c 100644 --- a/include/boost/any/unique_any.hpp +++ b/include/boost/any/unique_any.hpp @@ -17,23 +17,7 @@ /// \file boost/any/unique_any.hpp /// \brief \copybrief boost::anys::unique_any -#ifdef BOOST_NO_CXX11_RVALUE_REFERENCES -#error Header requires C++11 compatible compiler with move semantics -#endif - -#ifdef BOOST_NO_CXX11_DEFAULTED_FUNCTIONS -#error Header requires C++11 compatible compiler with defaulted functions -#endif - -#ifdef BOOST_NO_CXX11_SMART_PTR -#error Header requires C++11 compatible standard library with std::unique_ptr -#endif -#include - -#ifdef BOOST_NO_CXX11_HDR_INITIALIZER_LIST -#error Header requires C++11 compatible standard library with std::initializer_list -#endif - +#include // for std::unique_ptr #include #include @@ -41,6 +25,7 @@ #include #include +#include #include namespace boost { namespace anys { @@ -58,8 +43,6 @@ constexpr in_place_type_t in_place_type{}; /// \brief A class whose instances can hold instances of any /// type (including non-copyable and non-movable types). -/// -/// \pre C++11 compatible compiler. class unique_any { public: /// \post this->has_value() is false. diff --git a/meta/libraries.json b/meta/libraries.json index 77c8724..443cf96 100644 --- a/meta/libraries.json +++ b/meta/libraries.json @@ -12,5 +12,5 @@ "maintainers": [ "Antony Polukhin " ], - "cxxstd": "03" + "cxxstd": "11" } diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index dfaa6da..f738a6b 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -8,8 +8,16 @@ build-project unique_any ; +import ../../config/checks/config : requires ; + import testing ; +project + : source-location . + : requirements + [ requires cxx11_rvalue_references ] + ; + test-suite any : [ run any_test.cpp ] [ run any_test.cpp : : : off BOOST_NO_RTTI BOOST_NO_TYPEID : any_test_no_rtti ] diff --git a/test/any_test.cpp b/test/any_test.cpp index 5a30e37..cf38b10 100644 --- a/test/any_test.cpp +++ b/test/any_test.cpp @@ -35,7 +35,6 @@ static void test_with_func() s = boost::any_cast(returning_string2()); s = boost::any_cast(returning_string2()); -#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) #if !defined(__INTEL_COMPILER) && !defined(__ICL) && (!defined(_MSC_VER) || _MSC_VER != 1600) // Intel compiler thinks that it must choose the `any_cast(const any&)` function // instead of the `any_cast(const any&&)`. @@ -54,7 +53,6 @@ static void test_with_func() #endif s = boost::any_cast(returning_string2()); -#endif } int main() { diff --git a/test/any_test_cv_to_rv_failed.cpp b/test/any_test_cv_to_rv_failed.cpp index c168180..c474883 100644 --- a/test/any_test_cv_to_rv_failed.cpp +++ b/test/any_test_cv_to_rv_failed.cpp @@ -14,18 +14,6 @@ #include #include "test.hpp" -#include - -#ifdef BOOST_NO_CXX11_RVALUE_REFERENCES - -int main() -{ - BOOST_STATIC_ASSERT(false); - return EXIT_SUCCESS; -} - -#else - int main() { @@ -35,5 +23,3 @@ int main() return EXIT_SUCCESS; } -#endif - diff --git a/test/any_test_rv.cpp b/test/any_test_rv.cpp index b9fd872..6c4ae31 100644 --- a/test/any_test_rv.cpp +++ b/test/any_test_rv.cpp @@ -12,18 +12,6 @@ #include "move_test.hpp" -#ifdef BOOST_NO_CXX11_RVALUE_REFERENCES - -int main() -{ - return EXIT_SUCCESS; -} - -#else - int main() { return any_tests::move_tests::run_tests(); } - -#endif - diff --git a/test/any_test_temporary_to_ref_failed.cpp b/test/any_test_temporary_to_ref_failed.cpp index 6d5070f..73f0af3 100644 --- a/test/any_test_temporary_to_ref_failed.cpp +++ b/test/any_test_temporary_to_ref_failed.cpp @@ -14,17 +14,6 @@ #include #include "test.hpp" -#include - -#ifdef BOOST_NO_CXX11_RVALUE_REFERENCES - -int main() -{ - BOOST_STATIC_ASSERT(false); - return EXIT_SUCCESS; -} - -#else int main() @@ -34,5 +23,3 @@ int main() return EXIT_SUCCESS; } -#endif - diff --git a/test/appveyor.yml b/test/appveyor.yml index 5f4f4bf..84c26e6 100644 --- a/test/appveyor.yml +++ b/test/appveyor.yml @@ -21,7 +21,7 @@ init: # From this point and below code is same for all the Boost libs ############################################################################################################### -version: 1.64.{build}-{branch} +version: 1.84.{build}-{branch} # branches to build branches: @@ -32,9 +32,6 @@ skip_tags: true environment: matrix: - - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015 - TOOLSET: msvc-9.0,msvc-10.0,msvc-11.0,msvc-12.0 - ADDRMD: 32 - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 TOOLSET: msvc-14.1,clang-win CXXSTD: 14,17 diff --git a/test/basic_any_test_cv_to_rv_failed.cpp b/test/basic_any_test_cv_to_rv_failed.cpp index e35bca0..291c32f 100644 --- a/test/basic_any_test_cv_to_rv_failed.cpp +++ b/test/basic_any_test_cv_to_rv_failed.cpp @@ -2,7 +2,7 @@ // // See http://www.boost.org for most recent version, including documentation. // -// Copyright Antony Polukhin, 2013-2019. +// Copyright Antony Polukhin, 2013-2023. // Copyright Ruslan Arutyunyan, 2019-2021. // // Distributed under the Boost @@ -15,17 +15,6 @@ #include #include "test.hpp" -#include - -#ifdef BOOST_NO_CXX11_RVALUE_REFERENCES - -int main() -{ - BOOST_STATIC_ASSERT(false); - return EXIT_SUCCESS; -} - -#else int main() @@ -36,5 +25,3 @@ int main() return EXIT_SUCCESS; } -#endif - diff --git a/test/basic_any_test_large_object.cpp b/test/basic_any_test_large_object.cpp index 251ff94..6904e82 100644 --- a/test/basic_any_test_large_object.cpp +++ b/test/basic_any_test_large_object.cpp @@ -20,43 +20,25 @@ struct A { A() {} A(const A&) {} -#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES - A(A&&) BOOST_NOEXCEPT { + A(A&&) noexcept { ++move_ctors_count; } -#endif ~A() { ++destructors_count; } }; -#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES - template - T&& portable_move(T& value) { - return std::move(value); - } -#else - template - T& portable_move(T& value) { - return value; - } -#endif - int main() { { A a; boost::anys::basic_any<24, 8> any1(a); - boost::anys::basic_any<24, 8> any2(portable_move(any1)); - boost::anys::basic_any<24, 8> any3(portable_move(any2)); + boost::anys::basic_any<24, 8> any2(std::move(any1)); + boost::anys::basic_any<24, 8> any3(std::move(any2)); BOOST_TEST_EQ(move_ctors_count, 0); } -#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) BOOST_TEST_EQ(destructors_count, 2); -#else - BOOST_TEST_EQ(destructors_count, 4); -#endif return boost::report_errors(); } diff --git a/test/basic_any_test_rv.cpp b/test/basic_any_test_rv.cpp index 7d2a4a6..3ca700d 100644 --- a/test/basic_any_test_rv.cpp +++ b/test/basic_any_test_rv.cpp @@ -13,15 +13,6 @@ #include "move_test.hpp" -#ifdef BOOST_NO_CXX11_RVALUE_REFERENCES - -int main() -{ - return EXIT_SUCCESS; -} - -#else - int main() { const int res1 = any_tests::move_tests >::run_tests(); if (res1) return 1; @@ -36,4 +27,3 @@ int main() { if (res4) return 4; } -#endif diff --git a/test/basic_any_test_small_object.cpp b/test/basic_any_test_small_object.cpp index 0018b68..c886e21 100644 --- a/test/basic_any_test_small_object.cpp +++ b/test/basic_any_test_small_object.cpp @@ -20,52 +20,27 @@ struct A { A() {} A(const A&) {} -#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES - A(A&&) BOOST_NOEXCEPT { + A(A&&) noexcept { ++move_ctors_count; } -#endif ~A() { ++destructors_count; } }; -#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES - template - T&& portable_move(T& value) { - return std::move(value); - } -#else - template - T& portable_move(T& value) { - return value; - } -#endif - int main() { #if !defined(__GNUC__) || __GNUC__ > 4 { A a; boost::anys::basic_any<24, 8> any1(a); - boost::anys::basic_any<24, 8> any2(portable_move(any1)); - boost::anys::basic_any<24, 8> any3(portable_move(any2)); -#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && !defined(BOOST_NO_CXX11_NOEXCEPT) + boost::anys::basic_any<24, 8> any2(std::move(any1)); + boost::anys::basic_any<24, 8> any3(std::move(any2)); BOOST_TEST_EQ(move_ctors_count, 2); -#else - BOOST_TEST_EQ(move_ctors_count, 0); -#endif } -#if defined(BOOST_NO_CXX11_NOEXCEPT) && !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) - // The move constructor is not marked with noexcept, so the large_manager is used. - // Moving large_manager data is just swapping pointers without calling destructors. - BOOST_TEST_EQ(destructors_count, 2); -#else BOOST_TEST_EQ(destructors_count, 4); -#endif - #endif // #if !defined(__GNUC__) || __GNUC__ > 4 return boost::report_errors(); } diff --git a/test/basic_any_test_temporary_to_ref_failed.cpp b/test/basic_any_test_temporary_to_ref_failed.cpp index ac72480..3e3ea7d 100644 --- a/test/basic_any_test_temporary_to_ref_failed.cpp +++ b/test/basic_any_test_temporary_to_ref_failed.cpp @@ -15,18 +15,6 @@ #include #include "test.hpp" -#include - -#ifdef BOOST_NO_CXX11_RVALUE_REFERENCES - -int main() -{ - BOOST_STATIC_ASSERT(false); - return EXIT_SUCCESS; -} - -#else - int main() { @@ -35,5 +23,3 @@ int main() return EXIT_SUCCESS; } -#endif - diff --git a/test/move_test.hpp b/test/move_test.hpp index 8d5004a..16d50fd 100644 --- a/test/move_test.hpp +++ b/test/move_test.hpp @@ -18,8 +18,6 @@ #include #include -#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES - namespace any_tests { template @@ -108,25 +106,19 @@ struct move_tests // test definitions move_copy_conting_class value0; move_copy_conting_class::copy_count = 0; move_copy_conting_class::moves_count = 0; -#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION + Any value(boost::move(value0)); -#else - Any value(value0); -#endif check_false(value.empty(), "empty"); check_equal(value.type(), boost::typeindex::type_id(), "type"); check_non_null(boost::any_cast(&value), "any_cast"); -#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION check_equal( move_copy_conting_class::copy_count, 0u, "checking copy counts"); check_equal( move_copy_conting_class::moves_count, 1u, "checking move counts"); -#endif - } static void test_move_assignment_from_value() @@ -135,25 +127,18 @@ struct move_tests // test definitions Any value; move_copy_conting_class::copy_count = 0; move_copy_conting_class::moves_count = 0; -#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION value = boost::move(value0); -#else - value = value0; -#endif check_false(value.empty(), "empty"); check_equal(value.type(), boost::typeindex::type_id(), "type"); check_non_null(boost::any_cast(&value), "any_cast"); -#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION check_equal( move_copy_conting_class::copy_count, 0u, "checking copy counts"); check_equal( move_copy_conting_class::moves_count, 1u, "checking move counts"); -#endif - } static void test_copy_construction_from_value() @@ -299,5 +284,3 @@ unsigned int move_tests::move_copy_conting_class::copy_count = 0; } // namespace any_tests #endif // BOOST_ANY_TESTS_MOVE_TEST_HPP_INCLUDED - -#endif // MOVE_TEST_INCLUDED diff --git a/test/unique_any/Jamfile.v2 b/test/unique_any/Jamfile.v2 index eda0dfd..caef00d 100644 --- a/test/unique_any/Jamfile.v2 +++ b/test/unique_any/Jamfile.v2 @@ -15,7 +15,7 @@ import testing ; project : source-location . : requirements - [ requires cxx11 ] + [ requires cxx11_rvalue_references ] ; test-suite unique_any :