[NFC][RemoveDIs] Prefer iterators over inst-pointers in InstCombine
[llvm-project.git] / libcxx / include / any
blobb3ac5871c42fc2c8849cba2f074e86845be67163
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 //===----------------------------------------------------------------------===//
10 #ifndef _LIBCPP_ANY
11 #define _LIBCPP_ANY
14    any synopsis
16 namespace std {
18   class bad_any_cast : public bad_cast
19   {
20   public:
21     virtual const char* what() const noexcept;
22   };
24   class any
25   {
26   public:
28     // 6.3.1 any construct/destruct
29     any() noexcept;
31     any(const any& other);
32     any(any&& other) noexcept;
34     template <class ValueType>
35       any(ValueType&& value);
37     ~any();
39     // 6.3.2 any assignments
40     any& operator=(const any& rhs);
41     any& operator=(any&& rhs) noexcept;
43     template <class ValueType>
44       any& operator=(ValueType&& rhs);
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;
54     // 6.3.4 any observers
55     bool has_value() const noexcept;
56     const type_info& type() const noexcept;
57   };
59    // 6.4 Non-member functions
60   void swap(any& x, any& y) noexcept;
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);
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);
74   template<class ValueType>
75     const ValueType* any_cast(const any* operand) noexcept;
76   template<class ValueType>
77     ValueType* any_cast(any* operand) noexcept;
79 } // namespace std
83 #include <__assert> // all public C++ headers provide the assertion handler
84 #include <__availability>
85 #include <__config>
86 #include <__memory/allocator.h>
87 #include <__memory/allocator_destructor.h>
88 #include <__memory/allocator_traits.h>
89 #include <__memory/unique_ptr.h>
90 #include <__type_traits/add_const.h>
91 #include <__type_traits/add_pointer.h>
92 #include <__type_traits/aligned_storage.h>
93 #include <__type_traits/alignment_of.h>
94 #include <__type_traits/conditional.h>
95 #include <__type_traits/decay.h>
96 #include <__type_traits/is_constructible.h>
97 #include <__type_traits/is_copy_constructible.h>
98 #include <__type_traits/is_function.h>
99 #include <__type_traits/is_nothrow_move_constructible.h>
100 #include <__type_traits/is_reference.h>
101 #include <__type_traits/is_same.h>
102 #include <__type_traits/remove_cv.h>
103 #include <__type_traits/remove_cvref.h>
104 #include <__type_traits/remove_reference.h>
105 #include <__utility/forward.h>
106 #include <__utility/in_place.h>
107 #include <__utility/move.h>
108 #include <__utility/unreachable.h>
109 #include <__verbose_abort>
110 #include <initializer_list>
111 #include <typeinfo>
112 #include <version>
114 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
115 #  pragma GCC system_header
116 #endif
118 _LIBCPP_PUSH_MACROS
119 #include <__undef_macros>
121 namespace std {
122 class _LIBCPP_EXPORTED_FROM_ABI _LIBCPP_AVAILABILITY_BAD_ANY_CAST bad_any_cast : public bad_cast
124 public:
125     const char* what() const _NOEXCEPT override;
127 } // namespace std
129 _LIBCPP_BEGIN_NAMESPACE_STD
131 #if _LIBCPP_STD_VER >= 17
133 _LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
134 _LIBCPP_AVAILABILITY_THROW_BAD_ANY_CAST
135 void __throw_bad_any_cast()
137 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
138     throw bad_any_cast();
139 #else
140     _LIBCPP_VERBOSE_ABORT("bad_any_cast was thrown in -fno-exceptions mode");
141 #endif
144 // Forward declarations
145 class _LIBCPP_TEMPLATE_VIS any;
147 template <class _ValueType>
148 _LIBCPP_INLINE_VISIBILITY
149 add_pointer_t<add_const_t<_ValueType>>
150 any_cast(any const *) _NOEXCEPT;
152 template <class _ValueType>
153 _LIBCPP_INLINE_VISIBILITY
154 add_pointer_t<_ValueType> any_cast(any *) _NOEXCEPT;
156 namespace __any_imp
158   _LIBCPP_SUPPRESS_DEPRECATED_PUSH
159   using _Buffer = aligned_storage_t<3*sizeof(void*), alignment_of<void*>::value>;
160   _LIBCPP_SUPPRESS_DEPRECATED_POP
162   template <class _Tp>
163   using _IsSmallObject = integral_constant<bool
164         , sizeof(_Tp) <= sizeof(_Buffer)
165           && alignment_of<_Buffer>::value
166              % alignment_of<_Tp>::value == 0
167           && is_nothrow_move_constructible<_Tp>::value
168         >;
170   enum class _Action {
171     _Destroy,
172     _Copy,
173     _Move,
174     _Get,
175     _TypeInfo
176   };
178   template <class _Tp> struct _SmallHandler;
179   template <class _Tp> struct _LargeHandler;
181   template <class _Tp>
182   struct  _LIBCPP_TEMPLATE_VIS __unique_typeinfo { static constexpr int __id = 0; };
183   template <class _Tp> constexpr int __unique_typeinfo<_Tp>::__id;
185   template <class _Tp>
186   inline _LIBCPP_INLINE_VISIBILITY
187   constexpr const void* __get_fallback_typeid() {
188       return &__unique_typeinfo<remove_cv_t<remove_reference_t<_Tp>>>::__id;
189   }
191   template <class _Tp>
192   inline _LIBCPP_INLINE_VISIBILITY
193   bool __compare_typeid(type_info const* __id, const void* __fallback_id)
194   {
195 #if !defined(_LIBCPP_HAS_NO_RTTI)
196       if (__id && *__id == typeid(_Tp))
197           return true;
198 #endif
199       if (!__id && __fallback_id == __any_imp::__get_fallback_typeid<_Tp>())
200           return true;
201       return false;
202   }
204   template <class _Tp>
205   using _Handler = conditional_t<
206     _IsSmallObject<_Tp>::value, _SmallHandler<_Tp>, _LargeHandler<_Tp>>;
208 } // namespace __any_imp
210 class _LIBCPP_TEMPLATE_VIS any
212 public:
213   // construct/destruct
214   _LIBCPP_INLINE_VISIBILITY
215   constexpr any() _NOEXCEPT : __h_(nullptr) {}
217   _LIBCPP_INLINE_VISIBILITY
218   any(any const & __other) : __h_(nullptr)
219   {
220     if (__other.__h_) __other.__call(_Action::_Copy, this);
221   }
223   _LIBCPP_INLINE_VISIBILITY
224   any(any && __other) _NOEXCEPT : __h_(nullptr)
225   {
226     if (__other.__h_) __other.__call(_Action::_Move, this);
227   }
229   template <
230       class _ValueType
231     , class _Tp = decay_t<_ValueType>
232     , class = enable_if_t<
233         !is_same<_Tp, any>::value &&
234         !__is_inplace_type<_ValueType>::value &&
235         is_copy_constructible<_Tp>::value>
236     >
237   _LIBCPP_INLINE_VISIBILITY
238   any(_ValueType && __value);
240   template <class _ValueType, class ..._Args,
241     class _Tp = decay_t<_ValueType>,
242     class = enable_if_t<
243         is_constructible<_Tp, _Args...>::value &&
244         is_copy_constructible<_Tp>::value
245     >
246   >
247   _LIBCPP_INLINE_VISIBILITY
248   explicit any(in_place_type_t<_ValueType>, _Args&&... __args);
250   template <class _ValueType, class _Up, class ..._Args,
251     class _Tp = decay_t<_ValueType>,
252     class = enable_if_t<
253         is_constructible<_Tp, initializer_list<_Up>&, _Args...>::value &&
254         is_copy_constructible<_Tp>::value>
255   >
256   _LIBCPP_INLINE_VISIBILITY
257   explicit any(in_place_type_t<_ValueType>, initializer_list<_Up>, _Args&&... __args);
259   _LIBCPP_INLINE_VISIBILITY
260   ~any() { this->reset(); }
262   // assignments
263   _LIBCPP_INLINE_VISIBILITY
264   any & operator=(any const & __rhs) {
265     any(__rhs).swap(*this);
266     return *this;
267   }
269   _LIBCPP_INLINE_VISIBILITY
270   any & operator=(any && __rhs) _NOEXCEPT {
271     any(_VSTD::move(__rhs)).swap(*this);
272     return *this;
273   }
275   template <
276       class _ValueType
277     , class _Tp = decay_t<_ValueType>
278     , class = enable_if_t<
279           !is_same<_Tp, any>::value
280           && is_copy_constructible<_Tp>::value>
281     >
282   _LIBCPP_INLINE_VISIBILITY
283   any & operator=(_ValueType && __rhs);
285   template <class _ValueType, class ..._Args,
286     class _Tp = decay_t<_ValueType>,
287     class = enable_if_t<
288         is_constructible<_Tp, _Args...>::value &&
289         is_copy_constructible<_Tp>::value>
290     >
291   _LIBCPP_INLINE_VISIBILITY
292   _Tp& emplace(_Args&&...);
294   template <class _ValueType, class _Up, class ..._Args,
295     class _Tp = decay_t<_ValueType>,
296     class = enable_if_t<
297         is_constructible<_Tp, initializer_list<_Up>&, _Args...>::value &&
298         is_copy_constructible<_Tp>::value>
299   >
300   _LIBCPP_INLINE_VISIBILITY
301   _Tp& emplace(initializer_list<_Up>, _Args&&...);
303   // 6.3.3 any modifiers
304   _LIBCPP_INLINE_VISIBILITY
305   void reset() _NOEXCEPT { if (__h_) this->__call(_Action::_Destroy); }
307   _LIBCPP_INLINE_VISIBILITY
308   void swap(any & __rhs) _NOEXCEPT;
310   // 6.3.4 any observers
311   _LIBCPP_INLINE_VISIBILITY
312   bool has_value() const _NOEXCEPT { return __h_ != nullptr; }
314 #if !defined(_LIBCPP_HAS_NO_RTTI)
315   _LIBCPP_INLINE_VISIBILITY
316   const type_info & type() const _NOEXCEPT {
317     if (__h_) {
318         return *static_cast<type_info const *>(this->__call(_Action::_TypeInfo));
319     } else {
320         return typeid(void);
321     }
322   }
323 #endif
325 private:
326     typedef __any_imp::_Action _Action;
327     using _HandleFuncPtr =  void* (*)(_Action, any const *, any *, const type_info *,
328       const void* __fallback_info);
330     union _Storage {
331         _LIBCPP_HIDE_FROM_ABI constexpr _Storage() : __ptr(nullptr) {}
332         void *  __ptr;
333         __any_imp::_Buffer __buf;
334     };
336     _LIBCPP_INLINE_VISIBILITY
337     void * __call(_Action __a, any * __other = nullptr,
338                   type_info const * __info = nullptr,
339                    const void* __fallback_info = nullptr) const
340     {
341         return __h_(__a, this, __other, __info, __fallback_info);
342     }
344     _LIBCPP_INLINE_VISIBILITY
345     void * __call(_Action __a, any * __other = nullptr,
346                   type_info const * __info = nullptr,
347                   const void* __fallback_info = nullptr)
348     {
349         return __h_(__a, this, __other, __info, __fallback_info);
350     }
352     template <class>
353     friend struct __any_imp::_SmallHandler;
354     template <class>
355     friend struct __any_imp::_LargeHandler;
357     template <class _ValueType>
358     friend add_pointer_t<add_const_t<_ValueType>>
359     any_cast(any const *) _NOEXCEPT;
361     template <class _ValueType>
362     friend add_pointer_t<_ValueType>
363     any_cast(any *) _NOEXCEPT;
365     _HandleFuncPtr __h_ = nullptr;
366     _Storage __s_;
369 namespace __any_imp
371   template <class _Tp>
372   struct _LIBCPP_TEMPLATE_VIS _SmallHandler
373   {
374      _LIBCPP_INLINE_VISIBILITY
375      static void* __handle(_Action __act, any const * __this, any * __other,
376                            type_info const * __info, const void* __fallback_info)
377      {
378         switch (__act)
379         {
380         case _Action::_Destroy:
381           __destroy(const_cast<any &>(*__this));
382           return nullptr;
383         case _Action::_Copy:
384             __copy(*__this, *__other);
385             return nullptr;
386         case _Action::_Move:
387           __move(const_cast<any &>(*__this), *__other);
388           return nullptr;
389         case _Action::_Get:
390             return __get(const_cast<any &>(*__this), __info, __fallback_info);
391         case _Action::_TypeInfo:
392           return __type_info();
393         }
394         __libcpp_unreachable();
395     }
397     template <class ..._Args>
398     _LIBCPP_INLINE_VISIBILITY
399     static _Tp& __create(any & __dest, _Args&&... __args) {
400         typedef allocator<_Tp> _Alloc;
401         typedef allocator_traits<_Alloc> _ATraits;
402         _Alloc __a;
403         _Tp * __ret = static_cast<_Tp*>(static_cast<void*>(&__dest.__s_.__buf));
404         _ATraits::construct(__a, __ret, _VSTD::forward<_Args>(__args)...);
405         __dest.__h_ = &_SmallHandler::__handle;
406         return *__ret;
407     }
409   private:
410     _LIBCPP_INLINE_VISIBILITY
411     static void __destroy(any & __this) {
412         typedef allocator<_Tp> _Alloc;
413         typedef allocator_traits<_Alloc> _ATraits;
414         _Alloc __a;
415         _Tp * __p = static_cast<_Tp *>(static_cast<void*>(&__this.__s_.__buf));
416         _ATraits::destroy(__a, __p);
417         __this.__h_ = nullptr;
418     }
420     _LIBCPP_INLINE_VISIBILITY
421     static void __copy(any const & __this, any & __dest) {
422         _SmallHandler::__create(__dest, *static_cast<_Tp const *>(
423             static_cast<void const *>(&__this.__s_.__buf)));
424     }
426     _LIBCPP_INLINE_VISIBILITY
427     static void __move(any & __this, any & __dest) {
428         _SmallHandler::__create(__dest, _VSTD::move(
429             *static_cast<_Tp*>(static_cast<void*>(&__this.__s_.__buf))));
430         __destroy(__this);
431     }
433     _LIBCPP_INLINE_VISIBILITY
434     static void* __get(any & __this,
435                        type_info const * __info,
436                        const void* __fallback_id)
437     {
438         if (__any_imp::__compare_typeid<_Tp>(__info, __fallback_id))
439             return static_cast<void*>(&__this.__s_.__buf);
440         return nullptr;
441     }
443     _LIBCPP_INLINE_VISIBILITY
444     static void* __type_info()
445     {
446 #if !defined(_LIBCPP_HAS_NO_RTTI)
447         return const_cast<void*>(static_cast<void const *>(&typeid(_Tp)));
448 #else
449         return nullptr;
450 #endif
451     }
452   };
454   template <class _Tp>
455   struct _LIBCPP_TEMPLATE_VIS _LargeHandler
456   {
457     _LIBCPP_INLINE_VISIBILITY
458     static void* __handle(_Action __act, any const * __this,
459                           any * __other, type_info const * __info,
460                           void const* __fallback_info)
461     {
462         switch (__act)
463         {
464         case _Action::_Destroy:
465           __destroy(const_cast<any &>(*__this));
466           return nullptr;
467         case _Action::_Copy:
468           __copy(*__this, *__other);
469           return nullptr;
470         case _Action::_Move:
471           __move(const_cast<any &>(*__this), *__other);
472           return nullptr;
473         case _Action::_Get:
474             return __get(const_cast<any &>(*__this), __info, __fallback_info);
475         case _Action::_TypeInfo:
476           return __type_info();
477         }
478         __libcpp_unreachable();
479     }
481     template <class ..._Args>
482     _LIBCPP_INLINE_VISIBILITY
483     static _Tp& __create(any & __dest, _Args&&... __args) {
484         typedef allocator<_Tp> _Alloc;
485         typedef allocator_traits<_Alloc> _ATraits;
486         typedef __allocator_destructor<_Alloc> _Dp;
487         _Alloc __a;
488         unique_ptr<_Tp, _Dp> __hold(_ATraits::allocate(__a, 1), _Dp(__a, 1));
489         _Tp * __ret = __hold.get();
490         _ATraits::construct(__a, __ret, _VSTD::forward<_Args>(__args)...);
491         __dest.__s_.__ptr = __hold.release();
492         __dest.__h_ = &_LargeHandler::__handle;
493         return *__ret;
494     }
496   private:
498     _LIBCPP_INLINE_VISIBILITY
499     static void __destroy(any & __this){
500         typedef allocator<_Tp> _Alloc;
501         typedef allocator_traits<_Alloc> _ATraits;
502         _Alloc __a;
503         _Tp * __p = static_cast<_Tp *>(__this.__s_.__ptr);
504         _ATraits::destroy(__a, __p);
505         _ATraits::deallocate(__a, __p, 1);
506         __this.__h_ = nullptr;
507     }
509     _LIBCPP_INLINE_VISIBILITY
510     static void __copy(any const & __this, any & __dest) {
511         _LargeHandler::__create(__dest, *static_cast<_Tp const *>(__this.__s_.__ptr));
512     }
514     _LIBCPP_INLINE_VISIBILITY
515     static void __move(any & __this, any & __dest) {
516       __dest.__s_.__ptr = __this.__s_.__ptr;
517       __dest.__h_ = &_LargeHandler::__handle;
518       __this.__h_ = nullptr;
519     }
521     _LIBCPP_INLINE_VISIBILITY
522     static void* __get(any & __this, type_info const * __info,
523                        void const* __fallback_info)
524     {
525         if (__any_imp::__compare_typeid<_Tp>(__info, __fallback_info))
526             return static_cast<void*>(__this.__s_.__ptr);
527         return nullptr;
529     }
531     _LIBCPP_INLINE_VISIBILITY
532     static void* __type_info()
533     {
534 #if !defined(_LIBCPP_HAS_NO_RTTI)
535         return const_cast<void*>(static_cast<void const *>(&typeid(_Tp)));
536 #else
537         return nullptr;
538 #endif
539     }
540   };
542 } // namespace __any_imp
545 template <class _ValueType, class _Tp, class>
546 any::any(_ValueType && __v) : __h_(nullptr)
548   __any_imp::_Handler<_Tp>::__create(*this, _VSTD::forward<_ValueType>(__v));
551 template <class _ValueType, class ..._Args, class _Tp, class>
552 any::any(in_place_type_t<_ValueType>, _Args&&... __args) {
553   __any_imp::_Handler<_Tp>::__create(*this, _VSTD::forward<_Args>(__args)...);
556 template <class _ValueType, class _Up, class ..._Args, class _Tp, class>
557 any::any(in_place_type_t<_ValueType>, initializer_list<_Up> __il, _Args&&... __args) {
558   __any_imp::_Handler<_Tp>::__create(*this, __il, _VSTD::forward<_Args>(__args)...);
561 template <class _ValueType, class, class>
562 inline _LIBCPP_INLINE_VISIBILITY
563 any & any::operator=(_ValueType && __v)
565   any(_VSTD::forward<_ValueType>(__v)).swap(*this);
566   return *this;
569 template <class _ValueType, class ..._Args, class _Tp, class>
570 inline _LIBCPP_INLINE_VISIBILITY
571 _Tp& any::emplace(_Args&&... __args) {
572   reset();
573   return __any_imp::_Handler<_Tp>::__create(*this, _VSTD::forward<_Args>(__args)...);
576 template <class _ValueType, class _Up, class ..._Args, class _Tp, class>
577 inline _LIBCPP_INLINE_VISIBILITY
578 _Tp& any::emplace(initializer_list<_Up> __il, _Args&&... __args) {
579   reset();
580   return __any_imp::_Handler<_Tp>::__create(*this, __il, _VSTD::forward<_Args>(__args)...);
583 inline _LIBCPP_INLINE_VISIBILITY
584 void any::swap(any & __rhs) _NOEXCEPT
586     if (this == &__rhs)
587       return;
588     if (__h_ && __rhs.__h_) {
589         any __tmp;
590         __rhs.__call(_Action::_Move, &__tmp);
591         this->__call(_Action::_Move, &__rhs);
592         __tmp.__call(_Action::_Move, this);
593     }
594     else if (__h_) {
595         this->__call(_Action::_Move, &__rhs);
596     }
597     else if (__rhs.__h_) {
598         __rhs.__call(_Action::_Move, this);
599     }
602 // 6.4 Non-member functions
604 inline _LIBCPP_INLINE_VISIBILITY
605 void swap(any & __lhs, any & __rhs) _NOEXCEPT
607     __lhs.swap(__rhs);
610 template <class _Tp, class ..._Args>
611 inline _LIBCPP_INLINE_VISIBILITY
612 any make_any(_Args&&... __args) {
613     return any(in_place_type<_Tp>, _VSTD::forward<_Args>(__args)...);
616 template <class _Tp, class _Up, class ..._Args>
617 inline _LIBCPP_INLINE_VISIBILITY
618 any make_any(initializer_list<_Up> __il, _Args&&... __args) {
619     return any(in_place_type<_Tp>, __il, _VSTD::forward<_Args>(__args)...);
622 template <class _ValueType>
623 inline _LIBCPP_INLINE_VISIBILITY
624 _LIBCPP_AVAILABILITY_THROW_BAD_ANY_CAST
625 _ValueType any_cast(any const & __v)
627     using _RawValueType = __remove_cvref_t<_ValueType>;
628     static_assert(is_constructible<_ValueType, _RawValueType const &>::value,
629                   "ValueType is required to be a const lvalue reference "
630                   "or a CopyConstructible type");
631     auto __tmp = _VSTD::any_cast<add_const_t<_RawValueType>>(&__v);
632     if (__tmp == nullptr)
633         __throw_bad_any_cast();
634     return static_cast<_ValueType>(*__tmp);
637 template <class _ValueType>
638 inline _LIBCPP_INLINE_VISIBILITY
639 _LIBCPP_AVAILABILITY_THROW_BAD_ANY_CAST
640 _ValueType any_cast(any & __v)
642     using _RawValueType = __remove_cvref_t<_ValueType>;
643     static_assert(is_constructible<_ValueType, _RawValueType &>::value,
644                   "ValueType is required to be an lvalue reference "
645                   "or a CopyConstructible type");
646     auto __tmp = _VSTD::any_cast<_RawValueType>(&__v);
647     if (__tmp == nullptr)
648         __throw_bad_any_cast();
649     return static_cast<_ValueType>(*__tmp);
652 template <class _ValueType>
653 inline _LIBCPP_INLINE_VISIBILITY
654 _LIBCPP_AVAILABILITY_THROW_BAD_ANY_CAST
655 _ValueType any_cast(any && __v)
657     using _RawValueType = __remove_cvref_t<_ValueType>;
658     static_assert(is_constructible<_ValueType, _RawValueType>::value,
659                   "ValueType is required to be an rvalue reference "
660                   "or a CopyConstructible type");
661     auto __tmp = _VSTD::any_cast<_RawValueType>(&__v);
662     if (__tmp == nullptr)
663         __throw_bad_any_cast();
664     return static_cast<_ValueType>(_VSTD::move(*__tmp));
667 template <class _ValueType>
668 inline _LIBCPP_INLINE_VISIBILITY
669 add_pointer_t<add_const_t<_ValueType>>
670 any_cast(any const * __any) _NOEXCEPT
672     static_assert(!is_reference<_ValueType>::value,
673                   "_ValueType may not be a reference.");
674     return _VSTD::any_cast<_ValueType>(const_cast<any *>(__any));
677 template <class _RetType>
678 inline _LIBCPP_INLINE_VISIBILITY
679 _RetType __pointer_or_func_cast(void* __p, /*IsFunction*/false_type) noexcept {
680   return static_cast<_RetType>(__p);
683 template <class _RetType>
684 inline _LIBCPP_INLINE_VISIBILITY
685 _RetType __pointer_or_func_cast(void*, /*IsFunction*/true_type) noexcept {
686   return nullptr;
689 template <class _ValueType>
690 _LIBCPP_HIDE_FROM_ABI
691 add_pointer_t<_ValueType>
692 any_cast(any * __any) _NOEXCEPT
694     using __any_imp::_Action;
695     static_assert(!is_reference<_ValueType>::value,
696                   "_ValueType may not be a reference.");
697     typedef add_pointer_t<_ValueType> _ReturnType;
698     if (__any && __any->__h_) {
699       void *__p = __any->__call(_Action::_Get, nullptr,
700 #if !defined(_LIBCPP_HAS_NO_RTTI)
701                           &typeid(_ValueType),
702 #else
703                           nullptr,
704 #endif
705                           __any_imp::__get_fallback_typeid<_ValueType>());
706         return _VSTD::__pointer_or_func_cast<_ReturnType>(
707             __p, is_function<_ValueType>{});
708     }
709     return nullptr;
712 #endif // _LIBCPP_STD_VER >= 17
714 _LIBCPP_END_NAMESPACE_STD
716 _LIBCPP_POP_MACROS
718 #if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 17
719 #  include <chrono>
720 #endif
722 #if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
723 #  include <atomic>
724 #  include <concepts>
725 #  include <cstdlib>
726 #  include <iosfwd>
727 #  include <iterator>
728 #  include <memory>
729 #  include <stdexcept>
730 #  include <type_traits>
731 #  include <variant>
732 #endif
734 #endif // _LIBCPP_ANY