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