1// -*- C++ -*- 2//===----------------------------------------------------------------------===// 3// 4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 5// See https://llvm.org/LICENSE.txt for license information. 6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 7// 8//===----------------------------------------------------------------------===// 9 10#ifndef _LIBCPP_ANY 11#define _LIBCPP_ANY 12 13/* 14 any synopsis 15 16namespace std { 17 18 class bad_any_cast : public bad_cast 19 { 20 public: 21 virtual const char* what() const noexcept; 22 }; 23 24 class any 25 { 26 public: 27 28 // 6.3.1 any construct/destruct 29 any() noexcept; 30 31 any(const any& other); 32 any(any&& other) noexcept; 33 34 template <class ValueType> 35 any(ValueType&& value); 36 37 ~any(); 38 39 // 6.3.2 any assignments 40 any& operator=(const any& rhs); 41 any& operator=(any&& rhs) noexcept; 42 43 template <class ValueType> 44 any& operator=(ValueType&& rhs); 45 46 // 6.3.3 any modifiers 47 template <class ValueType, class... Args> 48 decay_t<ValueType>& emplace(Args&&... args); 49 template <class ValueType, class U, class... Args> 50 decay_t<ValueType>& emplace(initializer_list<U>, Args&&...); 51 void reset() noexcept; 52 void swap(any& rhs) noexcept; 53 54 // 6.3.4 any observers 55 bool has_value() const noexcept; 56 const type_info& type() const noexcept; 57 }; 58 59 // 6.4 Non-member functions 60 void swap(any& x, any& y) noexcept; 61 62 template <class T, class ...Args> 63 any make_any(Args&& ...args); 64 template <class T, class U, class ...Args> 65 any make_any(initializer_list<U>, Args&& ...args); 66 67 template<class ValueType> 68 ValueType any_cast(const any& operand); 69 template<class ValueType> 70 ValueType any_cast(any& operand); 71 template<class ValueType> 72 ValueType any_cast(any&& operand); 73 74 template<class ValueType> 75 const ValueType* any_cast(const any* operand) noexcept; 76 template<class ValueType> 77 ValueType* any_cast(any* operand) noexcept; 78 79} // namespace std 80 81*/ 82 83#include <__availability> 84#include <__config> 85#include <__memory/allocator.h> 86#include <__memory/allocator_destructor.h> 87#include <__memory/allocator_traits.h> 88#include <__memory/unique_ptr.h> 89#include <__type_traits/add_const.h> 90#include <__type_traits/add_pointer.h> 91#include <__type_traits/aligned_storage.h> 92#include <__type_traits/conditional.h> 93#include <__type_traits/decay.h> 94#include <__type_traits/is_constructible.h> 95#include <__type_traits/is_function.h> 96#include <__type_traits/is_nothrow_constructible.h> 97#include <__type_traits/is_reference.h> 98#include <__type_traits/is_same.h> 99#include <__type_traits/is_void.h> 100#include <__type_traits/remove_cv.h> 101#include <__type_traits/remove_cvref.h> 102#include <__type_traits/remove_reference.h> 103#include <__utility/forward.h> 104#include <__utility/in_place.h> 105#include <__utility/move.h> 106#include <__utility/unreachable.h> 107#include <__verbose_abort> 108#include <initializer_list> 109#include <typeinfo> 110#include <version> 111 112#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 113# pragma GCC system_header 114#endif 115 116_LIBCPP_PUSH_MACROS 117#include <__undef_macros> 118 119namespace std { 120class _LIBCPP_EXPORTED_FROM_ABI _LIBCPP_AVAILABILITY_BAD_ANY_CAST bad_any_cast : public bad_cast { 121public: 122 const char* what() const _NOEXCEPT override; 123}; 124} // namespace std 125 126_LIBCPP_BEGIN_NAMESPACE_STD 127 128#if _LIBCPP_STD_VER >= 17 129 130_LIBCPP_NORETURN inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_THROW_BAD_ANY_CAST void __throw_bad_any_cast() { 131# ifndef _LIBCPP_HAS_NO_EXCEPTIONS 132 throw bad_any_cast(); 133# else 134 _LIBCPP_VERBOSE_ABORT("bad_any_cast was thrown in -fno-exceptions mode"); 135# endif 136} 137 138// Forward declarations 139class _LIBCPP_TEMPLATE_VIS any; 140 141template <class _ValueType> 142_LIBCPP_HIDE_FROM_ABI add_pointer_t<add_const_t<_ValueType>> any_cast(any const*) _NOEXCEPT; 143 144template <class _ValueType> 145_LIBCPP_HIDE_FROM_ABI add_pointer_t<_ValueType> any_cast(any*) _NOEXCEPT; 146 147namespace __any_imp { 148_LIBCPP_SUPPRESS_DEPRECATED_PUSH 149using _Buffer = aligned_storage_t<3 * sizeof(void*), alignof(void*)>; 150_LIBCPP_SUPPRESS_DEPRECATED_POP 151 152template <class _Tp> 153using _IsSmallObject = 154 integral_constant<bool, 155 sizeof(_Tp) <= sizeof(_Buffer) && alignof(_Buffer) % alignof(_Tp) == 0 && 156 is_nothrow_move_constructible<_Tp>::value >; 157 158enum class _Action { _Destroy, _Copy, _Move, _Get, _TypeInfo }; 159 160template <class _Tp> 161struct _SmallHandler; 162template <class _Tp> 163struct _LargeHandler; 164 165template <class _Tp> 166struct _LIBCPP_TEMPLATE_VIS __unique_typeinfo { 167 static constexpr int __id = 0; 168}; 169template <class _Tp> 170constexpr int __unique_typeinfo<_Tp>::__id; 171 172template <class _Tp> 173inline _LIBCPP_HIDE_FROM_ABI constexpr const void* __get_fallback_typeid() { 174 return &__unique_typeinfo<remove_cv_t<remove_reference_t<_Tp>>>::__id; 175} 176 177template <class _Tp> 178inline _LIBCPP_HIDE_FROM_ABI bool __compare_typeid(type_info const* __id, const void* __fallback_id) { 179# if !defined(_LIBCPP_HAS_NO_RTTI) 180 if (__id && *__id == typeid(_Tp)) 181 return true; 182# endif 183 return !__id && __fallback_id == __any_imp::__get_fallback_typeid<_Tp>(); 184} 185 186template <class _Tp> 187using _Handler = conditional_t< _IsSmallObject<_Tp>::value, _SmallHandler<_Tp>, _LargeHandler<_Tp>>; 188 189} // namespace __any_imp 190 191class _LIBCPP_TEMPLATE_VIS any { 192public: 193 // construct/destruct 194 _LIBCPP_HIDE_FROM_ABI constexpr any() _NOEXCEPT : __h_(nullptr) {} 195 196 _LIBCPP_HIDE_FROM_ABI any(any const& __other) : __h_(nullptr) { 197 if (__other.__h_) 198 __other.__call(_Action::_Copy, this); 199 } 200 201 _LIBCPP_HIDE_FROM_ABI any(any&& __other) _NOEXCEPT : __h_(nullptr) { 202 if (__other.__h_) 203 __other.__call(_Action::_Move, this); 204 } 205 206 template < class _ValueType, 207 class _Tp = decay_t<_ValueType>, 208 class = enable_if_t< !is_same<_Tp, any>::value && !__is_inplace_type<_ValueType>::value && 209 is_copy_constructible<_Tp>::value> > 210 _LIBCPP_HIDE_FROM_ABI any(_ValueType&& __value); 211 212 template <class _ValueType, 213 class... _Args, 214 class _Tp = decay_t<_ValueType>, 215 class = enable_if_t< is_constructible<_Tp, _Args...>::value && is_copy_constructible<_Tp>::value > > 216 _LIBCPP_HIDE_FROM_ABI explicit any(in_place_type_t<_ValueType>, _Args&&... __args); 217 218 template <class _ValueType, 219 class _Up, 220 class... _Args, 221 class _Tp = decay_t<_ValueType>, 222 class = enable_if_t< is_constructible<_Tp, initializer_list<_Up>&, _Args...>::value && 223 is_copy_constructible<_Tp>::value> > 224 _LIBCPP_HIDE_FROM_ABI explicit any(in_place_type_t<_ValueType>, initializer_list<_Up>, _Args&&... __args); 225 226 _LIBCPP_HIDE_FROM_ABI ~any() { this->reset(); } 227 228 // assignments 229 _LIBCPP_HIDE_FROM_ABI any& operator=(any const& __rhs) { 230 any(__rhs).swap(*this); 231 return *this; 232 } 233 234 _LIBCPP_HIDE_FROM_ABI any& operator=(any&& __rhs) _NOEXCEPT { 235 any(std::move(__rhs)).swap(*this); 236 return *this; 237 } 238 239 template < class _ValueType, 240 class _Tp = decay_t<_ValueType>, 241 class = enable_if_t< !is_same<_Tp, any>::value && is_copy_constructible<_Tp>::value> > 242 _LIBCPP_HIDE_FROM_ABI any& operator=(_ValueType&& __rhs); 243 244 template <class _ValueType, 245 class... _Args, 246 class _Tp = decay_t<_ValueType>, 247 class = enable_if_t< is_constructible<_Tp, _Args...>::value && is_copy_constructible<_Tp>::value> > 248 _LIBCPP_HIDE_FROM_ABI _Tp& emplace(_Args&&...); 249 250 template <class _ValueType, 251 class _Up, 252 class... _Args, 253 class _Tp = decay_t<_ValueType>, 254 class = enable_if_t< is_constructible<_Tp, initializer_list<_Up>&, _Args...>::value && 255 is_copy_constructible<_Tp>::value> > 256 _LIBCPP_HIDE_FROM_ABI _Tp& emplace(initializer_list<_Up>, _Args&&...); 257 258 // 6.3.3 any modifiers 259 _LIBCPP_HIDE_FROM_ABI void reset() _NOEXCEPT { 260 if (__h_) 261 this->__call(_Action::_Destroy); 262 } 263 264 _LIBCPP_HIDE_FROM_ABI void swap(any& __rhs) _NOEXCEPT; 265 266 // 6.3.4 any observers 267 _LIBCPP_HIDE_FROM_ABI bool has_value() const _NOEXCEPT { return __h_ != nullptr; } 268 269# if !defined(_LIBCPP_HAS_NO_RTTI) 270 _LIBCPP_HIDE_FROM_ABI const type_info& type() const _NOEXCEPT { 271 if (__h_) { 272 return *static_cast<type_info const*>(this->__call(_Action::_TypeInfo)); 273 } else { 274 return typeid(void); 275 } 276 } 277# endif 278 279private: 280 typedef __any_imp::_Action _Action; 281 using _HandleFuncPtr = void* (*)(_Action, any const*, any*, const type_info*, const void* __fallback_info); 282 283 union _Storage { 284 _LIBCPP_HIDE_FROM_ABI constexpr _Storage() : __ptr(nullptr) {} 285 void* __ptr; 286 __any_imp::_Buffer __buf; 287 }; 288 289 _LIBCPP_HIDE_FROM_ABI void* 290 __call(_Action __a, any* __other = nullptr, type_info const* __info = nullptr, const void* __fallback_info = nullptr) 291 const { 292 return __h_(__a, this, __other, __info, __fallback_info); 293 } 294 295 _LIBCPP_HIDE_FROM_ABI void* __call( 296 _Action __a, any* __other = nullptr, type_info const* __info = nullptr, const void* __fallback_info = nullptr) { 297 return __h_(__a, this, __other, __info, __fallback_info); 298 } 299 300 template <class> 301 friend struct __any_imp::_SmallHandler; 302 template <class> 303 friend struct __any_imp::_LargeHandler; 304 305 template <class _ValueType> 306 friend add_pointer_t<add_const_t<_ValueType>> any_cast(any const*) _NOEXCEPT; 307 308 template <class _ValueType> 309 friend add_pointer_t<_ValueType> any_cast(any*) _NOEXCEPT; 310 311 _HandleFuncPtr __h_ = nullptr; 312 _Storage __s_; 313}; 314 315namespace __any_imp { 316template <class _Tp> 317struct _LIBCPP_TEMPLATE_VIS _SmallHandler { 318 _LIBCPP_HIDE_FROM_ABI static void* 319 __handle(_Action __act, any const* __this, any* __other, type_info const* __info, const void* __fallback_info) { 320 switch (__act) { 321 case _Action::_Destroy: 322 __destroy(const_cast<any&>(*__this)); 323 return nullptr; 324 case _Action::_Copy: 325 __copy(*__this, *__other); 326 return nullptr; 327 case _Action::_Move: 328 __move(const_cast<any&>(*__this), *__other); 329 return nullptr; 330 case _Action::_Get: 331 return __get(const_cast<any&>(*__this), __info, __fallback_info); 332 case _Action::_TypeInfo: 333 return __type_info(); 334 } 335 __libcpp_unreachable(); 336 } 337 338 template <class... _Args> 339 _LIBCPP_HIDE_FROM_ABI static _Tp& __create(any& __dest, _Args&&... __args) { 340 typedef allocator<_Tp> _Alloc; 341 typedef allocator_traits<_Alloc> _ATraits; 342 _Alloc __a; 343 _Tp* __ret = static_cast<_Tp*>(static_cast<void*>(&__dest.__s_.__buf)); 344 _ATraits::construct(__a, __ret, std::forward<_Args>(__args)...); 345 __dest.__h_ = &_SmallHandler::__handle; 346 return *__ret; 347 } 348 349private: 350 _LIBCPP_HIDE_FROM_ABI static void __destroy(any& __this) { 351 typedef allocator<_Tp> _Alloc; 352 typedef allocator_traits<_Alloc> _ATraits; 353 _Alloc __a; 354 _Tp* __p = static_cast<_Tp*>(static_cast<void*>(&__this.__s_.__buf)); 355 _ATraits::destroy(__a, __p); 356 __this.__h_ = nullptr; 357 } 358 359 _LIBCPP_HIDE_FROM_ABI static void __copy(any const& __this, any& __dest) { 360 _SmallHandler::__create(__dest, *static_cast<_Tp const*>(static_cast<void const*>(&__this.__s_.__buf))); 361 } 362 363 _LIBCPP_HIDE_FROM_ABI static void __move(any& __this, any& __dest) { 364 _SmallHandler::__create(__dest, std::move(*static_cast<_Tp*>(static_cast<void*>(&__this.__s_.__buf)))); 365 __destroy(__this); 366 } 367 368 _LIBCPP_HIDE_FROM_ABI static void* __get(any& __this, type_info const* __info, const void* __fallback_id) { 369 if (__any_imp::__compare_typeid<_Tp>(__info, __fallback_id)) 370 return static_cast<void*>(&__this.__s_.__buf); 371 return nullptr; 372 } 373 374 _LIBCPP_HIDE_FROM_ABI static void* __type_info() { 375# if !defined(_LIBCPP_HAS_NO_RTTI) 376 return const_cast<void*>(static_cast<void const*>(&typeid(_Tp))); 377# else 378 return nullptr; 379# endif 380 } 381}; 382 383template <class _Tp> 384struct _LIBCPP_TEMPLATE_VIS _LargeHandler { 385 _LIBCPP_HIDE_FROM_ABI static void* 386 __handle(_Action __act, any const* __this, any* __other, type_info const* __info, void const* __fallback_info) { 387 switch (__act) { 388 case _Action::_Destroy: 389 __destroy(const_cast<any&>(*__this)); 390 return nullptr; 391 case _Action::_Copy: 392 __copy(*__this, *__other); 393 return nullptr; 394 case _Action::_Move: 395 __move(const_cast<any&>(*__this), *__other); 396 return nullptr; 397 case _Action::_Get: 398 return __get(const_cast<any&>(*__this), __info, __fallback_info); 399 case _Action::_TypeInfo: 400 return __type_info(); 401 } 402 __libcpp_unreachable(); 403 } 404 405 template <class... _Args> 406 _LIBCPP_HIDE_FROM_ABI static _Tp& __create(any& __dest, _Args&&... __args) { 407 typedef allocator<_Tp> _Alloc; 408 typedef allocator_traits<_Alloc> _ATraits; 409 typedef __allocator_destructor<_Alloc> _Dp; 410 _Alloc __a; 411 unique_ptr<_Tp, _Dp> __hold(_ATraits::allocate(__a, 1), _Dp(__a, 1)); 412 _Tp* __ret = __hold.get(); 413 _ATraits::construct(__a, __ret, std::forward<_Args>(__args)...); 414 __dest.__s_.__ptr = __hold.release(); 415 __dest.__h_ = &_LargeHandler::__handle; 416 return *__ret; 417 } 418 419private: 420 _LIBCPP_HIDE_FROM_ABI static void __destroy(any& __this) { 421 typedef allocator<_Tp> _Alloc; 422 typedef allocator_traits<_Alloc> _ATraits; 423 _Alloc __a; 424 _Tp* __p = static_cast<_Tp*>(__this.__s_.__ptr); 425 _ATraits::destroy(__a, __p); 426 _ATraits::deallocate(__a, __p, 1); 427 __this.__h_ = nullptr; 428 } 429 430 _LIBCPP_HIDE_FROM_ABI static void __copy(any const& __this, any& __dest) { 431 _LargeHandler::__create(__dest, *static_cast<_Tp const*>(__this.__s_.__ptr)); 432 } 433 434 _LIBCPP_HIDE_FROM_ABI static void __move(any& __this, any& __dest) { 435 __dest.__s_.__ptr = __this.__s_.__ptr; 436 __dest.__h_ = &_LargeHandler::__handle; 437 __this.__h_ = nullptr; 438 } 439 440 _LIBCPP_HIDE_FROM_ABI static void* __get(any& __this, type_info const* __info, void const* __fallback_info) { 441 if (__any_imp::__compare_typeid<_Tp>(__info, __fallback_info)) 442 return static_cast<void*>(__this.__s_.__ptr); 443 return nullptr; 444 } 445 446 _LIBCPP_HIDE_FROM_ABI static void* __type_info() { 447# if !defined(_LIBCPP_HAS_NO_RTTI) 448 return const_cast<void*>(static_cast<void const*>(&typeid(_Tp))); 449# else 450 return nullptr; 451# endif 452 } 453}; 454 455} // namespace __any_imp 456 457template <class _ValueType, class _Tp, class> 458any::any(_ValueType&& __v) : __h_(nullptr) { 459 __any_imp::_Handler<_Tp>::__create(*this, std::forward<_ValueType>(__v)); 460} 461 462template <class _ValueType, class... _Args, class _Tp, class> 463any::any(in_place_type_t<_ValueType>, _Args&&... __args) { 464 __any_imp::_Handler<_Tp>::__create(*this, std::forward<_Args>(__args)...); 465} 466 467template <class _ValueType, class _Up, class... _Args, class _Tp, class> 468any::any(in_place_type_t<_ValueType>, initializer_list<_Up> __il, _Args&&... __args) { 469 __any_imp::_Handler<_Tp>::__create(*this, __il, std::forward<_Args>(__args)...); 470} 471 472template <class _ValueType, class, class> 473inline _LIBCPP_HIDE_FROM_ABI any& any::operator=(_ValueType&& __v) { 474 any(std::forward<_ValueType>(__v)).swap(*this); 475 return *this; 476} 477 478template <class _ValueType, class... _Args, class _Tp, class> 479inline _LIBCPP_HIDE_FROM_ABI _Tp& any::emplace(_Args&&... __args) { 480 reset(); 481 return __any_imp::_Handler<_Tp>::__create(*this, std::forward<_Args>(__args)...); 482} 483 484template <class _ValueType, class _Up, class... _Args, class _Tp, class> 485inline _LIBCPP_HIDE_FROM_ABI _Tp& any::emplace(initializer_list<_Up> __il, _Args&&... __args) { 486 reset(); 487 return __any_imp::_Handler<_Tp>::__create(*this, __il, std::forward<_Args>(__args)...); 488} 489 490inline _LIBCPP_HIDE_FROM_ABI void any::swap(any& __rhs) _NOEXCEPT { 491 if (this == &__rhs) 492 return; 493 if (__h_ && __rhs.__h_) { 494 any __tmp; 495 __rhs.__call(_Action::_Move, &__tmp); 496 this->__call(_Action::_Move, &__rhs); 497 __tmp.__call(_Action::_Move, this); 498 } else if (__h_) { 499 this->__call(_Action::_Move, &__rhs); 500 } else if (__rhs.__h_) { 501 __rhs.__call(_Action::_Move, this); 502 } 503} 504 505// 6.4 Non-member functions 506 507inline _LIBCPP_HIDE_FROM_ABI void swap(any& __lhs, any& __rhs) _NOEXCEPT { __lhs.swap(__rhs); } 508 509template <class _Tp, class... _Args> 510inline _LIBCPP_HIDE_FROM_ABI any make_any(_Args&&... __args) { 511 return any(in_place_type<_Tp>, std::forward<_Args>(__args)...); 512} 513 514template <class _Tp, class _Up, class... _Args> 515inline _LIBCPP_HIDE_FROM_ABI any make_any(initializer_list<_Up> __il, _Args&&... __args) { 516 return any(in_place_type<_Tp>, __il, std::forward<_Args>(__args)...); 517} 518 519template <class _ValueType> 520inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_THROW_BAD_ANY_CAST _ValueType any_cast(any const& __v) { 521 using _RawValueType = __remove_cvref_t<_ValueType>; 522 static_assert(is_constructible<_ValueType, _RawValueType const&>::value, 523 "ValueType is required to be a const lvalue reference " 524 "or a CopyConstructible type"); 525 auto __tmp = std::any_cast<add_const_t<_RawValueType>>(&__v); 526 if (__tmp == nullptr) 527 __throw_bad_any_cast(); 528 return static_cast<_ValueType>(*__tmp); 529} 530 531template <class _ValueType> 532inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_THROW_BAD_ANY_CAST _ValueType any_cast(any& __v) { 533 using _RawValueType = __remove_cvref_t<_ValueType>; 534 static_assert(is_constructible<_ValueType, _RawValueType&>::value, 535 "ValueType is required to be an lvalue reference " 536 "or a CopyConstructible type"); 537 auto __tmp = std::any_cast<_RawValueType>(&__v); 538 if (__tmp == nullptr) 539 __throw_bad_any_cast(); 540 return static_cast<_ValueType>(*__tmp); 541} 542 543template <class _ValueType> 544inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_THROW_BAD_ANY_CAST _ValueType any_cast(any&& __v) { 545 using _RawValueType = __remove_cvref_t<_ValueType>; 546 static_assert(is_constructible<_ValueType, _RawValueType>::value, 547 "ValueType is required to be an rvalue reference " 548 "or a CopyConstructible type"); 549 auto __tmp = std::any_cast<_RawValueType>(&__v); 550 if (__tmp == nullptr) 551 __throw_bad_any_cast(); 552 return static_cast<_ValueType>(std::move(*__tmp)); 553} 554 555template <class _ValueType> 556inline _LIBCPP_HIDE_FROM_ABI add_pointer_t<add_const_t<_ValueType>> any_cast(any const* __any) _NOEXCEPT { 557 static_assert(!is_void_v<_ValueType>, "_ValueType may not be void."); 558 static_assert(!is_reference<_ValueType>::value, "_ValueType may not be a reference."); 559 return std::any_cast<_ValueType>(const_cast<any*>(__any)); 560} 561 562template <class _RetType> 563inline _LIBCPP_HIDE_FROM_ABI _RetType __pointer_or_func_cast(void* __p, /*IsFunction*/ false_type) noexcept { 564 return static_cast<_RetType>(__p); 565} 566 567template <class _RetType> 568inline _LIBCPP_HIDE_FROM_ABI _RetType __pointer_or_func_cast(void*, /*IsFunction*/ true_type) noexcept { 569 return nullptr; 570} 571 572template <class _ValueType> 573_LIBCPP_HIDE_FROM_ABI add_pointer_t<_ValueType> any_cast(any* __any) _NOEXCEPT { 574 using __any_imp::_Action; 575 static_assert(!is_void_v<_ValueType>, "_ValueType may not be void."); 576 static_assert(!is_reference<_ValueType>::value, "_ValueType may not be a reference."); 577 typedef add_pointer_t<_ValueType> _ReturnType; 578 if (__any && __any->__h_) { 579 void* __p = __any->__call( 580 _Action::_Get, 581 nullptr, 582# if !defined(_LIBCPP_HAS_NO_RTTI) 583 &typeid(_ValueType), 584# else 585 nullptr, 586# endif 587 __any_imp::__get_fallback_typeid<_ValueType>()); 588 return std::__pointer_or_func_cast<_ReturnType>(__p, is_function<_ValueType>{}); 589 } 590 return nullptr; 591} 592 593#endif // _LIBCPP_STD_VER >= 17 594 595_LIBCPP_END_NAMESPACE_STD 596 597_LIBCPP_POP_MACROS 598 599#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 17 600# include <chrono> 601#endif 602 603#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20 604# include <atomic> 605# include <concepts> 606# include <cstdlib> 607# include <iosfwd> 608# include <iterator> 609# include <memory> 610# include <stdexcept> 611# include <type_traits> 612# include <variant> 613#endif 614 615#endif // _LIBCPP_ANY 616