Back to home page

EIC code displayed by LXR

 
 

    


Warning, /include/c++/v1/any is written in an unsupported language. File is not indexed.

0001 // -*- C++ -*-
0002 //===----------------------------------------------------------------------===//
0003 //
0004 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0005 // See https://llvm.org/LICENSE.txt for license information.
0006 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0007 //
0008 //===----------------------------------------------------------------------===//
0009 
0010 #ifndef _LIBCPP_ANY
0011 #define _LIBCPP_ANY
0012 
0013 /*
0014    any synopsis
0015 
0016 namespace std {
0017 
0018   class bad_any_cast : public bad_cast
0019   {
0020   public:
0021     virtual const char* what() const noexcept;
0022   };
0023 
0024   class any
0025   {
0026   public:
0027 
0028     // 6.3.1 any construct/destruct
0029     any() noexcept;
0030 
0031     any(const any& other);
0032     any(any&& other) noexcept;
0033 
0034     template <class ValueType>
0035       any(ValueType&& value);
0036 
0037     ~any();
0038 
0039     // 6.3.2 any assignments
0040     any& operator=(const any& rhs);
0041     any& operator=(any&& rhs) noexcept;
0042 
0043     template <class ValueType>
0044       any& operator=(ValueType&& rhs);
0045 
0046     // 6.3.3 any modifiers
0047     template <class ValueType, class... Args>
0048       decay_t<ValueType>& emplace(Args&&... args);
0049     template <class ValueType, class U, class... Args>
0050       decay_t<ValueType>& emplace(initializer_list<U>, Args&&...);
0051     void reset() noexcept;
0052     void swap(any& rhs) noexcept;
0053 
0054     // 6.3.4 any observers
0055     bool has_value() const noexcept;
0056     const type_info& type() const noexcept;
0057   };
0058 
0059    // 6.4 Non-member functions
0060   void swap(any& x, any& y) noexcept;
0061 
0062   template <class T, class ...Args>
0063     any make_any(Args&& ...args);
0064   template <class T, class U, class ...Args>
0065     any make_any(initializer_list<U>, Args&& ...args);
0066 
0067   template<class ValueType>
0068     ValueType any_cast(const any& operand);
0069   template<class ValueType>
0070     ValueType any_cast(any& operand);
0071   template<class ValueType>
0072     ValueType any_cast(any&& operand);
0073 
0074   template<class ValueType>
0075     const ValueType* any_cast(const any* operand) noexcept;
0076   template<class ValueType>
0077     ValueType* any_cast(any* operand) noexcept;
0078 
0079 } // namespace std
0080 
0081 */
0082 
0083 #if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
0084 #  include <__cxx03/any>
0085 #else
0086 #  include <__config>
0087 #  include <__memory/allocator.h>
0088 #  include <__memory/allocator_destructor.h>
0089 #  include <__memory/allocator_traits.h>
0090 #  include <__memory/unique_ptr.h>
0091 #  include <__type_traits/add_cv_quals.h>
0092 #  include <__type_traits/add_pointer.h>
0093 #  include <__type_traits/aligned_storage.h>
0094 #  include <__type_traits/conditional.h>
0095 #  include <__type_traits/decay.h>
0096 #  include <__type_traits/enable_if.h>
0097 #  include <__type_traits/is_constructible.h>
0098 #  include <__type_traits/is_function.h>
0099 #  include <__type_traits/is_nothrow_constructible.h>
0100 #  include <__type_traits/is_reference.h>
0101 #  include <__type_traits/is_same.h>
0102 #  include <__type_traits/is_void.h>
0103 #  include <__type_traits/remove_cv.h>
0104 #  include <__type_traits/remove_cvref.h>
0105 #  include <__type_traits/remove_reference.h>
0106 #  include <__utility/forward.h>
0107 #  include <__utility/in_place.h>
0108 #  include <__utility/move.h>
0109 #  include <__utility/unreachable.h>
0110 #  include <__verbose_abort>
0111 #  include <initializer_list>
0112 #  include <typeinfo>
0113 #  include <version>
0114 
0115 #  if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0116 #    pragma GCC system_header
0117 #  endif
0118 
0119 _LIBCPP_PUSH_MACROS
0120 #  include <__undef_macros>
0121 
0122 namespace std {
0123 class _LIBCPP_EXPORTED_FROM_ABI _LIBCPP_AVAILABILITY_BAD_ANY_CAST bad_any_cast : public bad_cast {
0124 public:
0125   const char* what() const _NOEXCEPT override;
0126 };
0127 } // namespace std
0128 
0129 _LIBCPP_BEGIN_NAMESPACE_STD
0130 
0131 #  if _LIBCPP_STD_VER >= 17
0132 
0133 [[noreturn]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_THROW_BAD_ANY_CAST void __throw_bad_any_cast() {
0134 #    if _LIBCPP_HAS_EXCEPTIONS
0135   throw bad_any_cast();
0136 #    else
0137   _LIBCPP_VERBOSE_ABORT("bad_any_cast was thrown in -fno-exceptions mode");
0138 #    endif
0139 }
0140 
0141 // Forward declarations
0142 class _LIBCPP_TEMPLATE_VIS any;
0143 
0144 template <class _ValueType>
0145 _LIBCPP_HIDE_FROM_ABI add_pointer_t<add_const_t<_ValueType>> any_cast(any const*) _NOEXCEPT;
0146 
0147 template <class _ValueType>
0148 _LIBCPP_HIDE_FROM_ABI add_pointer_t<_ValueType> any_cast(any*) _NOEXCEPT;
0149 
0150 namespace __any_imp {
0151 _LIBCPP_SUPPRESS_DEPRECATED_PUSH
0152 using _Buffer _LIBCPP_NODEBUG = aligned_storage_t<3 * sizeof(void*), alignof(void*)>;
0153 _LIBCPP_SUPPRESS_DEPRECATED_POP
0154 
0155 template <class _Tp>
0156 using _IsSmallObject _LIBCPP_NODEBUG =
0157     integral_constant<bool,
0158                       sizeof(_Tp) <= sizeof(_Buffer) && alignof(_Buffer) % alignof(_Tp) == 0 &&
0159                           is_nothrow_move_constructible<_Tp>::value >;
0160 
0161 enum class _Action { _Destroy, _Copy, _Move, _Get, _TypeInfo };
0162 
0163 template <class _Tp>
0164 struct _SmallHandler;
0165 template <class _Tp>
0166 struct _LargeHandler;
0167 
0168 template <class _Tp>
0169 struct _LIBCPP_TEMPLATE_VIS __unique_typeinfo {
0170   static constexpr int __id = 0;
0171 };
0172 
0173 template <class _Tp>
0174 inline _LIBCPP_HIDE_FROM_ABI constexpr const void* __get_fallback_typeid() {
0175   return &__unique_typeinfo<remove_cv_t<remove_reference_t<_Tp>>>::__id;
0176 }
0177 
0178 template <class _Tp>
0179 inline _LIBCPP_HIDE_FROM_ABI bool __compare_typeid(type_info const* __id, const void* __fallback_id) {
0180 #    if _LIBCPP_HAS_RTTI
0181   if (__id && *__id == typeid(_Tp))
0182     return true;
0183 #    endif
0184   return !__id && __fallback_id == __any_imp::__get_fallback_typeid<_Tp>();
0185 }
0186 
0187 template <class _Tp>
0188 using _Handler _LIBCPP_NODEBUG = conditional_t< _IsSmallObject<_Tp>::value, _SmallHandler<_Tp>, _LargeHandler<_Tp>>;
0189 
0190 } // namespace __any_imp
0191 
0192 class _LIBCPP_TEMPLATE_VIS any {
0193 public:
0194   // construct/destruct
0195   _LIBCPP_HIDE_FROM_ABI constexpr any() _NOEXCEPT : __h_(nullptr) {}
0196 
0197   _LIBCPP_HIDE_FROM_ABI any(any const& __other) : __h_(nullptr) {
0198     if (__other.__h_)
0199       __other.__call(_Action::_Copy, this);
0200   }
0201 
0202   _LIBCPP_HIDE_FROM_ABI any(any&& __other) _NOEXCEPT : __h_(nullptr) {
0203     if (__other.__h_)
0204       __other.__call(_Action::_Move, this);
0205   }
0206 
0207   template < class _ValueType,
0208              class _Tp = decay_t<_ValueType>,
0209              class     = enable_if_t< !is_same<_Tp, any>::value && !__is_inplace_type<_ValueType>::value &&
0210                                       is_copy_constructible<_Tp>::value> >
0211   _LIBCPP_HIDE_FROM_ABI any(_ValueType&& __value);
0212 
0213   template <class _ValueType,
0214             class... _Args,
0215             class _Tp = decay_t<_ValueType>,
0216             class     = enable_if_t< is_constructible<_Tp, _Args...>::value && is_copy_constructible<_Tp>::value > >
0217   _LIBCPP_HIDE_FROM_ABI explicit any(in_place_type_t<_ValueType>, _Args&&... __args);
0218 
0219   template <class _ValueType,
0220             class _Up,
0221             class... _Args,
0222             class _Tp = decay_t<_ValueType>,
0223             class     = enable_if_t< is_constructible<_Tp, initializer_list<_Up>&, _Args...>::value &&
0224                                      is_copy_constructible<_Tp>::value> >
0225   _LIBCPP_HIDE_FROM_ABI explicit any(in_place_type_t<_ValueType>, initializer_list<_Up>, _Args&&... __args);
0226 
0227   _LIBCPP_HIDE_FROM_ABI ~any() { this->reset(); }
0228 
0229   // assignments
0230   _LIBCPP_HIDE_FROM_ABI any& operator=(any const& __rhs) {
0231     any(__rhs).swap(*this);
0232     return *this;
0233   }
0234 
0235   _LIBCPP_HIDE_FROM_ABI any& operator=(any&& __rhs) _NOEXCEPT {
0236     any(std::move(__rhs)).swap(*this);
0237     return *this;
0238   }
0239 
0240   template < class _ValueType,
0241              class _Tp = decay_t<_ValueType>,
0242              class     = enable_if_t< !is_same<_Tp, any>::value && is_copy_constructible<_Tp>::value> >
0243   _LIBCPP_HIDE_FROM_ABI any& operator=(_ValueType&& __rhs);
0244 
0245   template <class _ValueType,
0246             class... _Args,
0247             class _Tp = decay_t<_ValueType>,
0248             class     = enable_if_t< is_constructible<_Tp, _Args...>::value && is_copy_constructible<_Tp>::value> >
0249   _LIBCPP_HIDE_FROM_ABI _Tp& emplace(_Args&&...);
0250 
0251   template <class _ValueType,
0252             class _Up,
0253             class... _Args,
0254             class _Tp = decay_t<_ValueType>,
0255             class     = enable_if_t< is_constructible<_Tp, initializer_list<_Up>&, _Args...>::value &&
0256                                      is_copy_constructible<_Tp>::value> >
0257   _LIBCPP_HIDE_FROM_ABI _Tp& emplace(initializer_list<_Up>, _Args&&...);
0258 
0259   // 6.3.3 any modifiers
0260   _LIBCPP_HIDE_FROM_ABI void reset() _NOEXCEPT {
0261     if (__h_)
0262       this->__call(_Action::_Destroy);
0263   }
0264 
0265   _LIBCPP_HIDE_FROM_ABI void swap(any& __rhs) _NOEXCEPT;
0266 
0267   // 6.3.4 any observers
0268   _LIBCPP_HIDE_FROM_ABI bool has_value() const _NOEXCEPT { return __h_ != nullptr; }
0269 
0270 #    if _LIBCPP_HAS_RTTI
0271   _LIBCPP_HIDE_FROM_ABI const type_info& type() const _NOEXCEPT {
0272     if (__h_) {
0273       return *static_cast<type_info const*>(this->__call(_Action::_TypeInfo));
0274     } else {
0275       return typeid(void);
0276     }
0277   }
0278 #    endif
0279 
0280 private:
0281   using _Action _LIBCPP_NODEBUG = __any_imp::_Action;
0282   using _HandleFuncPtr
0283       _LIBCPP_NODEBUG = void* (*)(_Action, any const*, any*, const type_info*, const void* __fallback_info);
0284 
0285   union _Storage {
0286     _LIBCPP_HIDE_FROM_ABI constexpr _Storage() : __ptr(nullptr) {}
0287     void* __ptr;
0288     __any_imp::_Buffer __buf;
0289   };
0290 
0291   _LIBCPP_HIDE_FROM_ABI void*
0292   __call(_Action __a, any* __other = nullptr, type_info const* __info = nullptr, const void* __fallback_info = nullptr)
0293       const {
0294     return __h_(__a, this, __other, __info, __fallback_info);
0295   }
0296 
0297   _LIBCPP_HIDE_FROM_ABI void* __call(
0298       _Action __a, any* __other = nullptr, type_info const* __info = nullptr, const void* __fallback_info = nullptr) {
0299     return __h_(__a, this, __other, __info, __fallback_info);
0300   }
0301 
0302   template <class>
0303   friend struct __any_imp::_SmallHandler;
0304   template <class>
0305   friend struct __any_imp::_LargeHandler;
0306 
0307   template <class _ValueType>
0308   friend add_pointer_t<add_const_t<_ValueType>> any_cast(any const*) _NOEXCEPT;
0309 
0310   template <class _ValueType>
0311   friend add_pointer_t<_ValueType> any_cast(any*) _NOEXCEPT;
0312 
0313   _HandleFuncPtr __h_ = nullptr;
0314   _Storage __s_;
0315 };
0316 
0317 namespace __any_imp {
0318 template <class _Tp>
0319 struct _LIBCPP_TEMPLATE_VIS _SmallHandler {
0320   _LIBCPP_HIDE_FROM_ABI static void*
0321   __handle(_Action __act, any const* __this, any* __other, type_info const* __info, const void* __fallback_info) {
0322     switch (__act) {
0323     case _Action::_Destroy:
0324       __destroy(const_cast<any&>(*__this));
0325       return nullptr;
0326     case _Action::_Copy:
0327       __copy(*__this, *__other);
0328       return nullptr;
0329     case _Action::_Move:
0330       __move(const_cast<any&>(*__this), *__other);
0331       return nullptr;
0332     case _Action::_Get:
0333       return __get(const_cast<any&>(*__this), __info, __fallback_info);
0334     case _Action::_TypeInfo:
0335       return __type_info();
0336     }
0337     __libcpp_unreachable();
0338   }
0339 
0340   template <class... _Args>
0341   _LIBCPP_HIDE_FROM_ABI static _Tp& __create(any& __dest, _Args&&... __args) {
0342     typedef allocator<_Tp> _Alloc;
0343     typedef allocator_traits<_Alloc> _ATraits;
0344     _Alloc __a;
0345     _Tp* __ret = static_cast<_Tp*>(static_cast<void*>(&__dest.__s_.__buf));
0346     _ATraits::construct(__a, __ret, std::forward<_Args>(__args)...);
0347     __dest.__h_ = &_SmallHandler::__handle;
0348     return *__ret;
0349   }
0350 
0351 private:
0352   _LIBCPP_HIDE_FROM_ABI static void __destroy(any& __this) {
0353     typedef allocator<_Tp> _Alloc;
0354     typedef allocator_traits<_Alloc> _ATraits;
0355     _Alloc __a;
0356     _Tp* __p = static_cast<_Tp*>(static_cast<void*>(&__this.__s_.__buf));
0357     _ATraits::destroy(__a, __p);
0358     __this.__h_ = nullptr;
0359   }
0360 
0361   _LIBCPP_HIDE_FROM_ABI static void __copy(any const& __this, any& __dest) {
0362     _SmallHandler::__create(__dest, *static_cast<_Tp const*>(static_cast<void const*>(&__this.__s_.__buf)));
0363   }
0364 
0365   _LIBCPP_HIDE_FROM_ABI static void __move(any& __this, any& __dest) {
0366     _SmallHandler::__create(__dest, std::move(*static_cast<_Tp*>(static_cast<void*>(&__this.__s_.__buf))));
0367     __destroy(__this);
0368   }
0369 
0370   _LIBCPP_HIDE_FROM_ABI static void* __get(any& __this, type_info const* __info, const void* __fallback_id) {
0371     if (__any_imp::__compare_typeid<_Tp>(__info, __fallback_id))
0372       return static_cast<void*>(&__this.__s_.__buf);
0373     return nullptr;
0374   }
0375 
0376   _LIBCPP_HIDE_FROM_ABI static void* __type_info() {
0377 #    if _LIBCPP_HAS_RTTI
0378     return const_cast<void*>(static_cast<void const*>(&typeid(_Tp)));
0379 #    else
0380     return nullptr;
0381 #    endif
0382   }
0383 };
0384 
0385 template <class _Tp>
0386 struct _LIBCPP_TEMPLATE_VIS _LargeHandler {
0387   _LIBCPP_HIDE_FROM_ABI static void*
0388   __handle(_Action __act, any const* __this, any* __other, type_info const* __info, void const* __fallback_info) {
0389     switch (__act) {
0390     case _Action::_Destroy:
0391       __destroy(const_cast<any&>(*__this));
0392       return nullptr;
0393     case _Action::_Copy:
0394       __copy(*__this, *__other);
0395       return nullptr;
0396     case _Action::_Move:
0397       __move(const_cast<any&>(*__this), *__other);
0398       return nullptr;
0399     case _Action::_Get:
0400       return __get(const_cast<any&>(*__this), __info, __fallback_info);
0401     case _Action::_TypeInfo:
0402       return __type_info();
0403     }
0404     __libcpp_unreachable();
0405   }
0406 
0407   template <class... _Args>
0408   _LIBCPP_HIDE_FROM_ABI static _Tp& __create(any& __dest, _Args&&... __args) {
0409     typedef allocator<_Tp> _Alloc;
0410     typedef allocator_traits<_Alloc> _ATraits;
0411     typedef __allocator_destructor<_Alloc> _Dp;
0412     _Alloc __a;
0413     unique_ptr<_Tp, _Dp> __hold(_ATraits::allocate(__a, 1), _Dp(__a, 1));
0414     _Tp* __ret = __hold.get();
0415     _ATraits::construct(__a, __ret, std::forward<_Args>(__args)...);
0416     __dest.__s_.__ptr = __hold.release();
0417     __dest.__h_       = &_LargeHandler::__handle;
0418     return *__ret;
0419   }
0420 
0421 private:
0422   _LIBCPP_HIDE_FROM_ABI static void __destroy(any& __this) {
0423     typedef allocator<_Tp> _Alloc;
0424     typedef allocator_traits<_Alloc> _ATraits;
0425     _Alloc __a;
0426     _Tp* __p = static_cast<_Tp*>(__this.__s_.__ptr);
0427     _ATraits::destroy(__a, __p);
0428     _ATraits::deallocate(__a, __p, 1);
0429     __this.__h_ = nullptr;
0430   }
0431 
0432   _LIBCPP_HIDE_FROM_ABI static void __copy(any const& __this, any& __dest) {
0433     _LargeHandler::__create(__dest, *static_cast<_Tp const*>(__this.__s_.__ptr));
0434   }
0435 
0436   _LIBCPP_HIDE_FROM_ABI static void __move(any& __this, any& __dest) {
0437     __dest.__s_.__ptr = __this.__s_.__ptr;
0438     __dest.__h_       = &_LargeHandler::__handle;
0439     __this.__h_       = nullptr;
0440   }
0441 
0442   _LIBCPP_HIDE_FROM_ABI static void* __get(any& __this, type_info const* __info, void const* __fallback_info) {
0443     if (__any_imp::__compare_typeid<_Tp>(__info, __fallback_info))
0444       return static_cast<void*>(__this.__s_.__ptr);
0445     return nullptr;
0446   }
0447 
0448   _LIBCPP_HIDE_FROM_ABI static void* __type_info() {
0449 #    if _LIBCPP_HAS_RTTI
0450     return const_cast<void*>(static_cast<void const*>(&typeid(_Tp)));
0451 #    else
0452     return nullptr;
0453 #    endif
0454   }
0455 };
0456 
0457 } // namespace __any_imp
0458 
0459 template <class _ValueType, class _Tp, class>
0460 any::any(_ValueType&& __v) : __h_(nullptr) {
0461   __any_imp::_Handler<_Tp>::__create(*this, std::forward<_ValueType>(__v));
0462 }
0463 
0464 template <class _ValueType, class... _Args, class _Tp, class>
0465 any::any(in_place_type_t<_ValueType>, _Args&&... __args) {
0466   __any_imp::_Handler<_Tp>::__create(*this, std::forward<_Args>(__args)...);
0467 }
0468 
0469 template <class _ValueType, class _Up, class... _Args, class _Tp, class>
0470 any::any(in_place_type_t<_ValueType>, initializer_list<_Up> __il, _Args&&... __args) {
0471   __any_imp::_Handler<_Tp>::__create(*this, __il, std::forward<_Args>(__args)...);
0472 }
0473 
0474 template <class _ValueType, class, class>
0475 inline _LIBCPP_HIDE_FROM_ABI any& any::operator=(_ValueType&& __v) {
0476   any(std::forward<_ValueType>(__v)).swap(*this);
0477   return *this;
0478 }
0479 
0480 template <class _ValueType, class... _Args, class _Tp, class>
0481 inline _LIBCPP_HIDE_FROM_ABI _Tp& any::emplace(_Args&&... __args) {
0482   reset();
0483   return __any_imp::_Handler<_Tp>::__create(*this, std::forward<_Args>(__args)...);
0484 }
0485 
0486 template <class _ValueType, class _Up, class... _Args, class _Tp, class>
0487 inline _LIBCPP_HIDE_FROM_ABI _Tp& any::emplace(initializer_list<_Up> __il, _Args&&... __args) {
0488   reset();
0489   return __any_imp::_Handler<_Tp>::__create(*this, __il, std::forward<_Args>(__args)...);
0490 }
0491 
0492 inline _LIBCPP_HIDE_FROM_ABI void any::swap(any& __rhs) _NOEXCEPT {
0493   if (this == &__rhs)
0494     return;
0495   if (__h_ && __rhs.__h_) {
0496     any __tmp;
0497     __rhs.__call(_Action::_Move, &__tmp);
0498     this->__call(_Action::_Move, &__rhs);
0499     __tmp.__call(_Action::_Move, this);
0500   } else if (__h_) {
0501     this->__call(_Action::_Move, &__rhs);
0502   } else if (__rhs.__h_) {
0503     __rhs.__call(_Action::_Move, this);
0504   }
0505 }
0506 
0507 // 6.4 Non-member functions
0508 
0509 inline _LIBCPP_HIDE_FROM_ABI void swap(any& __lhs, any& __rhs) _NOEXCEPT { __lhs.swap(__rhs); }
0510 
0511 template <class _Tp, class... _Args>
0512 inline _LIBCPP_HIDE_FROM_ABI any make_any(_Args&&... __args) {
0513   return any(in_place_type<_Tp>, std::forward<_Args>(__args)...);
0514 }
0515 
0516 template <class _Tp, class _Up, class... _Args>
0517 inline _LIBCPP_HIDE_FROM_ABI any make_any(initializer_list<_Up> __il, _Args&&... __args) {
0518   return any(in_place_type<_Tp>, __il, std::forward<_Args>(__args)...);
0519 }
0520 
0521 template <class _ValueType>
0522 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_THROW_BAD_ANY_CAST _ValueType any_cast(any const& __v) {
0523   using _RawValueType = __remove_cvref_t<_ValueType>;
0524   static_assert(is_constructible<_ValueType, _RawValueType const&>::value,
0525                 "ValueType is required to be a const lvalue reference "
0526                 "or a CopyConstructible type");
0527   auto __tmp = std::any_cast<add_const_t<_RawValueType>>(&__v);
0528   if (__tmp == nullptr)
0529     __throw_bad_any_cast();
0530   return static_cast<_ValueType>(*__tmp);
0531 }
0532 
0533 template <class _ValueType>
0534 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_THROW_BAD_ANY_CAST _ValueType any_cast(any& __v) {
0535   using _RawValueType = __remove_cvref_t<_ValueType>;
0536   static_assert(is_constructible<_ValueType, _RawValueType&>::value,
0537                 "ValueType is required to be an lvalue reference "
0538                 "or a CopyConstructible type");
0539   auto __tmp = std::any_cast<_RawValueType>(&__v);
0540   if (__tmp == nullptr)
0541     __throw_bad_any_cast();
0542   return static_cast<_ValueType>(*__tmp);
0543 }
0544 
0545 template <class _ValueType>
0546 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_THROW_BAD_ANY_CAST _ValueType any_cast(any&& __v) {
0547   using _RawValueType = __remove_cvref_t<_ValueType>;
0548   static_assert(is_constructible<_ValueType, _RawValueType>::value,
0549                 "ValueType is required to be an rvalue reference "
0550                 "or a CopyConstructible type");
0551   auto __tmp = std::any_cast<_RawValueType>(&__v);
0552   if (__tmp == nullptr)
0553     __throw_bad_any_cast();
0554   return static_cast<_ValueType>(std::move(*__tmp));
0555 }
0556 
0557 template <class _ValueType>
0558 inline _LIBCPP_HIDE_FROM_ABI add_pointer_t<add_const_t<_ValueType>> any_cast(any const* __any) _NOEXCEPT {
0559   static_assert(!is_void_v<_ValueType>, "_ValueType may not be void.");
0560   static_assert(!is_reference<_ValueType>::value, "_ValueType may not be a reference.");
0561   return std::any_cast<_ValueType>(const_cast<any*>(__any));
0562 }
0563 
0564 template <class _RetType>
0565 inline _LIBCPP_HIDE_FROM_ABI _RetType __pointer_or_func_cast(void* __p, /*IsFunction*/ false_type) noexcept {
0566   return static_cast<_RetType>(__p);
0567 }
0568 
0569 template <class _RetType>
0570 inline _LIBCPP_HIDE_FROM_ABI _RetType __pointer_or_func_cast(void*, /*IsFunction*/ true_type) noexcept {
0571   return nullptr;
0572 }
0573 
0574 template <class _ValueType>
0575 _LIBCPP_HIDE_FROM_ABI add_pointer_t<_ValueType> any_cast(any* __any) _NOEXCEPT {
0576   using __any_imp::_Action;
0577   static_assert(!is_void_v<_ValueType>, "_ValueType may not be void.");
0578   static_assert(!is_reference<_ValueType>::value, "_ValueType may not be a reference.");
0579   typedef add_pointer_t<_ValueType> _ReturnType;
0580   if (__any && __any->__h_) {
0581     void* __p = __any->__call(
0582         _Action::_Get,
0583         nullptr,
0584 #    if _LIBCPP_HAS_RTTI
0585         &typeid(_ValueType),
0586 #    else
0587         nullptr,
0588 #    endif
0589         __any_imp::__get_fallback_typeid<_ValueType>());
0590     return std::__pointer_or_func_cast<_ReturnType>(__p, is_function<_ValueType>{});
0591   }
0592   return nullptr;
0593 }
0594 
0595 #  endif // _LIBCPP_STD_VER >= 17
0596 
0597 _LIBCPP_END_NAMESPACE_STD
0598 
0599 _LIBCPP_POP_MACROS
0600 
0601 #  if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 17
0602 #    include <chrono>
0603 #  endif
0604 
0605 #  if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
0606 #    include <atomic>
0607 #    include <concepts>
0608 #    include <cstdlib>
0609 #    include <iosfwd>
0610 #    include <iterator>
0611 #    include <memory>
0612 #    include <stdexcept>
0613 #    include <type_traits>
0614 #    include <variant>
0615 #  endif
0616 #endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
0617 
0618 #endif // _LIBCPP_ANY