• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <__config>
84#include <__memory/allocator.h>
85#include <__memory/allocator_destructor.h>
86#include <__memory/allocator_traits.h>
87#include <__memory/unique_ptr.h>
88#include <__type_traits/add_cv_quals.h>
89#include <__type_traits/add_pointer.h>
90#include <__type_traits/aligned_storage.h>
91#include <__type_traits/conditional.h>
92#include <__type_traits/decay.h>
93#include <__type_traits/enable_if.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[[noreturn]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_THROW_BAD_ANY_CAST void __throw_bad_any_cast() {
131#  if _LIBCPP_HAS_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};
169
170template <class _Tp>
171inline _LIBCPP_HIDE_FROM_ABI constexpr const void* __get_fallback_typeid() {
172  return &__unique_typeinfo<remove_cv_t<remove_reference_t<_Tp>>>::__id;
173}
174
175template <class _Tp>
176inline _LIBCPP_HIDE_FROM_ABI bool __compare_typeid(type_info const* __id, const void* __fallback_id) {
177#  if _LIBCPP_HAS_RTTI
178  if (__id && *__id == typeid(_Tp))
179    return true;
180#  endif
181  return !__id && __fallback_id == __any_imp::__get_fallback_typeid<_Tp>();
182}
183
184template <class _Tp>
185using _Handler = conditional_t< _IsSmallObject<_Tp>::value, _SmallHandler<_Tp>, _LargeHandler<_Tp>>;
186
187} // namespace __any_imp
188
189class _LIBCPP_TEMPLATE_VIS any {
190public:
191  // construct/destruct
192  _LIBCPP_HIDE_FROM_ABI constexpr any() _NOEXCEPT : __h_(nullptr) {}
193
194  _LIBCPP_HIDE_FROM_ABI any(any const& __other) : __h_(nullptr) {
195    if (__other.__h_)
196      __other.__call(_Action::_Copy, this);
197  }
198
199  _LIBCPP_HIDE_FROM_ABI any(any&& __other) _NOEXCEPT : __h_(nullptr) {
200    if (__other.__h_)
201      __other.__call(_Action::_Move, this);
202  }
203
204  template < class _ValueType,
205             class _Tp = decay_t<_ValueType>,
206             class     = enable_if_t< !is_same<_Tp, any>::value && !__is_inplace_type<_ValueType>::value &&
207                                      is_copy_constructible<_Tp>::value> >
208  _LIBCPP_HIDE_FROM_ABI any(_ValueType&& __value);
209
210  template <class _ValueType,
211            class... _Args,
212            class _Tp = decay_t<_ValueType>,
213            class     = enable_if_t< is_constructible<_Tp, _Args...>::value && is_copy_constructible<_Tp>::value > >
214  _LIBCPP_HIDE_FROM_ABI explicit any(in_place_type_t<_ValueType>, _Args&&... __args);
215
216  template <class _ValueType,
217            class _Up,
218            class... _Args,
219            class _Tp = decay_t<_ValueType>,
220            class     = enable_if_t< is_constructible<_Tp, initializer_list<_Up>&, _Args...>::value &&
221                                     is_copy_constructible<_Tp>::value> >
222  _LIBCPP_HIDE_FROM_ABI explicit any(in_place_type_t<_ValueType>, initializer_list<_Up>, _Args&&... __args);
223
224  _LIBCPP_HIDE_FROM_ABI ~any() { this->reset(); }
225
226  // assignments
227  _LIBCPP_HIDE_FROM_ABI any& operator=(any const& __rhs) {
228    any(__rhs).swap(*this);
229    return *this;
230  }
231
232  _LIBCPP_HIDE_FROM_ABI any& operator=(any&& __rhs) _NOEXCEPT {
233    any(std::move(__rhs)).swap(*this);
234    return *this;
235  }
236
237  template < class _ValueType,
238             class _Tp = decay_t<_ValueType>,
239             class     = enable_if_t< !is_same<_Tp, any>::value && is_copy_constructible<_Tp>::value> >
240  _LIBCPP_HIDE_FROM_ABI any& operator=(_ValueType&& __rhs);
241
242  template <class _ValueType,
243            class... _Args,
244            class _Tp = decay_t<_ValueType>,
245            class     = enable_if_t< is_constructible<_Tp, _Args...>::value && is_copy_constructible<_Tp>::value> >
246  _LIBCPP_HIDE_FROM_ABI _Tp& emplace(_Args&&...);
247
248  template <class _ValueType,
249            class _Up,
250            class... _Args,
251            class _Tp = decay_t<_ValueType>,
252            class     = enable_if_t< is_constructible<_Tp, initializer_list<_Up>&, _Args...>::value &&
253                                     is_copy_constructible<_Tp>::value> >
254  _LIBCPP_HIDE_FROM_ABI _Tp& emplace(initializer_list<_Up>, _Args&&...);
255
256  // 6.3.3 any modifiers
257  _LIBCPP_HIDE_FROM_ABI void reset() _NOEXCEPT {
258    if (__h_)
259      this->__call(_Action::_Destroy);
260  }
261
262  _LIBCPP_HIDE_FROM_ABI void swap(any& __rhs) _NOEXCEPT;
263
264  // 6.3.4 any observers
265  _LIBCPP_HIDE_FROM_ABI bool has_value() const _NOEXCEPT { return __h_ != nullptr; }
266
267#  if _LIBCPP_HAS_RTTI
268  _LIBCPP_HIDE_FROM_ABI const type_info& type() const _NOEXCEPT {
269    if (__h_) {
270      return *static_cast<type_info const*>(this->__call(_Action::_TypeInfo));
271    } else {
272      return typeid(void);
273    }
274  }
275#  endif
276
277private:
278  typedef __any_imp::_Action _Action;
279  using _HandleFuncPtr = void* (*)(_Action, any const*, any*, const type_info*, const void* __fallback_info);
280
281  union _Storage {
282    _LIBCPP_HIDE_FROM_ABI constexpr _Storage() : __ptr(nullptr) {}
283    void* __ptr;
284    __any_imp::_Buffer __buf;
285  };
286
287  _LIBCPP_HIDE_FROM_ABI void*
288  __call(_Action __a, any* __other = nullptr, type_info const* __info = nullptr, const void* __fallback_info = nullptr)
289      const {
290    return __h_(__a, this, __other, __info, __fallback_info);
291  }
292
293  _LIBCPP_HIDE_FROM_ABI void* __call(
294      _Action __a, any* __other = nullptr, type_info const* __info = nullptr, const void* __fallback_info = nullptr) {
295    return __h_(__a, this, __other, __info, __fallback_info);
296  }
297
298  template <class>
299  friend struct __any_imp::_SmallHandler;
300  template <class>
301  friend struct __any_imp::_LargeHandler;
302
303  template <class _ValueType>
304  friend add_pointer_t<add_const_t<_ValueType>> any_cast(any const*) _NOEXCEPT;
305
306  template <class _ValueType>
307  friend add_pointer_t<_ValueType> any_cast(any*) _NOEXCEPT;
308
309  _HandleFuncPtr __h_ = nullptr;
310  _Storage __s_;
311};
312
313namespace __any_imp {
314template <class _Tp>
315struct _LIBCPP_TEMPLATE_VIS _SmallHandler {
316  _LIBCPP_HIDE_FROM_ABI static void*
317  __handle(_Action __act, any const* __this, any* __other, type_info const* __info, const void* __fallback_info) {
318    switch (__act) {
319    case _Action::_Destroy:
320      __destroy(const_cast<any&>(*__this));
321      return nullptr;
322    case _Action::_Copy:
323      __copy(*__this, *__other);
324      return nullptr;
325    case _Action::_Move:
326      __move(const_cast<any&>(*__this), *__other);
327      return nullptr;
328    case _Action::_Get:
329      return __get(const_cast<any&>(*__this), __info, __fallback_info);
330    case _Action::_TypeInfo:
331      return __type_info();
332    }
333    __libcpp_unreachable();
334  }
335
336  template <class... _Args>
337  _LIBCPP_HIDE_FROM_ABI static _Tp& __create(any& __dest, _Args&&... __args) {
338    typedef allocator<_Tp> _Alloc;
339    typedef allocator_traits<_Alloc> _ATraits;
340    _Alloc __a;
341    _Tp* __ret = static_cast<_Tp*>(static_cast<void*>(&__dest.__s_.__buf));
342    _ATraits::construct(__a, __ret, std::forward<_Args>(__args)...);
343    __dest.__h_ = &_SmallHandler::__handle;
344    return *__ret;
345  }
346
347private:
348  _LIBCPP_HIDE_FROM_ABI static void __destroy(any& __this) {
349    typedef allocator<_Tp> _Alloc;
350    typedef allocator_traits<_Alloc> _ATraits;
351    _Alloc __a;
352    _Tp* __p = static_cast<_Tp*>(static_cast<void*>(&__this.__s_.__buf));
353    _ATraits::destroy(__a, __p);
354    __this.__h_ = nullptr;
355  }
356
357  _LIBCPP_HIDE_FROM_ABI static void __copy(any const& __this, any& __dest) {
358    _SmallHandler::__create(__dest, *static_cast<_Tp const*>(static_cast<void const*>(&__this.__s_.__buf)));
359  }
360
361  _LIBCPP_HIDE_FROM_ABI static void __move(any& __this, any& __dest) {
362    _SmallHandler::__create(__dest, std::move(*static_cast<_Tp*>(static_cast<void*>(&__this.__s_.__buf))));
363    __destroy(__this);
364  }
365
366  _LIBCPP_HIDE_FROM_ABI static void* __get(any& __this, type_info const* __info, const void* __fallback_id) {
367    if (__any_imp::__compare_typeid<_Tp>(__info, __fallback_id))
368      return static_cast<void*>(&__this.__s_.__buf);
369    return nullptr;
370  }
371
372  _LIBCPP_HIDE_FROM_ABI static void* __type_info() {
373#  if _LIBCPP_HAS_RTTI
374    return const_cast<void*>(static_cast<void const*>(&typeid(_Tp)));
375#  else
376    return nullptr;
377#  endif
378  }
379};
380
381template <class _Tp>
382struct _LIBCPP_TEMPLATE_VIS _LargeHandler {
383  _LIBCPP_HIDE_FROM_ABI static void*
384  __handle(_Action __act, any const* __this, any* __other, type_info const* __info, void const* __fallback_info) {
385    switch (__act) {
386    case _Action::_Destroy:
387      __destroy(const_cast<any&>(*__this));
388      return nullptr;
389    case _Action::_Copy:
390      __copy(*__this, *__other);
391      return nullptr;
392    case _Action::_Move:
393      __move(const_cast<any&>(*__this), *__other);
394      return nullptr;
395    case _Action::_Get:
396      return __get(const_cast<any&>(*__this), __info, __fallback_info);
397    case _Action::_TypeInfo:
398      return __type_info();
399    }
400    __libcpp_unreachable();
401  }
402
403  template <class... _Args>
404  _LIBCPP_HIDE_FROM_ABI static _Tp& __create(any& __dest, _Args&&... __args) {
405    typedef allocator<_Tp> _Alloc;
406    typedef allocator_traits<_Alloc> _ATraits;
407    typedef __allocator_destructor<_Alloc> _Dp;
408    _Alloc __a;
409    unique_ptr<_Tp, _Dp> __hold(_ATraits::allocate(__a, 1), _Dp(__a, 1));
410    _Tp* __ret = __hold.get();
411    _ATraits::construct(__a, __ret, std::forward<_Args>(__args)...);
412    __dest.__s_.__ptr = __hold.release();
413    __dest.__h_       = &_LargeHandler::__handle;
414    return *__ret;
415  }
416
417private:
418  _LIBCPP_HIDE_FROM_ABI static void __destroy(any& __this) {
419    typedef allocator<_Tp> _Alloc;
420    typedef allocator_traits<_Alloc> _ATraits;
421    _Alloc __a;
422    _Tp* __p = static_cast<_Tp*>(__this.__s_.__ptr);
423    _ATraits::destroy(__a, __p);
424    _ATraits::deallocate(__a, __p, 1);
425    __this.__h_ = nullptr;
426  }
427
428  _LIBCPP_HIDE_FROM_ABI static void __copy(any const& __this, any& __dest) {
429    _LargeHandler::__create(__dest, *static_cast<_Tp const*>(__this.__s_.__ptr));
430  }
431
432  _LIBCPP_HIDE_FROM_ABI static void __move(any& __this, any& __dest) {
433    __dest.__s_.__ptr = __this.__s_.__ptr;
434    __dest.__h_       = &_LargeHandler::__handle;
435    __this.__h_       = nullptr;
436  }
437
438  _LIBCPP_HIDE_FROM_ABI static void* __get(any& __this, type_info const* __info, void const* __fallback_info) {
439    if (__any_imp::__compare_typeid<_Tp>(__info, __fallback_info))
440      return static_cast<void*>(__this.__s_.__ptr);
441    return nullptr;
442  }
443
444  _LIBCPP_HIDE_FROM_ABI static void* __type_info() {
445#  if _LIBCPP_HAS_RTTI
446    return const_cast<void*>(static_cast<void const*>(&typeid(_Tp)));
447#  else
448    return nullptr;
449#  endif
450  }
451};
452
453} // namespace __any_imp
454
455template <class _ValueType, class _Tp, class>
456any::any(_ValueType&& __v) : __h_(nullptr) {
457  __any_imp::_Handler<_Tp>::__create(*this, std::forward<_ValueType>(__v));
458}
459
460template <class _ValueType, class... _Args, class _Tp, class>
461any::any(in_place_type_t<_ValueType>, _Args&&... __args) {
462  __any_imp::_Handler<_Tp>::__create(*this, std::forward<_Args>(__args)...);
463}
464
465template <class _ValueType, class _Up, class... _Args, class _Tp, class>
466any::any(in_place_type_t<_ValueType>, initializer_list<_Up> __il, _Args&&... __args) {
467  __any_imp::_Handler<_Tp>::__create(*this, __il, std::forward<_Args>(__args)...);
468}
469
470template <class _ValueType, class, class>
471inline _LIBCPP_HIDE_FROM_ABI any& any::operator=(_ValueType&& __v) {
472  any(std::forward<_ValueType>(__v)).swap(*this);
473  return *this;
474}
475
476template <class _ValueType, class... _Args, class _Tp, class>
477inline _LIBCPP_HIDE_FROM_ABI _Tp& any::emplace(_Args&&... __args) {
478  reset();
479  return __any_imp::_Handler<_Tp>::__create(*this, std::forward<_Args>(__args)...);
480}
481
482template <class _ValueType, class _Up, class... _Args, class _Tp, class>
483inline _LIBCPP_HIDE_FROM_ABI _Tp& any::emplace(initializer_list<_Up> __il, _Args&&... __args) {
484  reset();
485  return __any_imp::_Handler<_Tp>::__create(*this, __il, std::forward<_Args>(__args)...);
486}
487
488inline _LIBCPP_HIDE_FROM_ABI void any::swap(any& __rhs) _NOEXCEPT {
489  if (this == &__rhs)
490    return;
491  if (__h_ && __rhs.__h_) {
492    any __tmp;
493    __rhs.__call(_Action::_Move, &__tmp);
494    this->__call(_Action::_Move, &__rhs);
495    __tmp.__call(_Action::_Move, this);
496  } else if (__h_) {
497    this->__call(_Action::_Move, &__rhs);
498  } else if (__rhs.__h_) {
499    __rhs.__call(_Action::_Move, this);
500  }
501}
502
503// 6.4 Non-member functions
504
505inline _LIBCPP_HIDE_FROM_ABI void swap(any& __lhs, any& __rhs) _NOEXCEPT { __lhs.swap(__rhs); }
506
507template <class _Tp, class... _Args>
508inline _LIBCPP_HIDE_FROM_ABI any make_any(_Args&&... __args) {
509  return any(in_place_type<_Tp>, std::forward<_Args>(__args)...);
510}
511
512template <class _Tp, class _Up, class... _Args>
513inline _LIBCPP_HIDE_FROM_ABI any make_any(initializer_list<_Up> __il, _Args&&... __args) {
514  return any(in_place_type<_Tp>, __il, std::forward<_Args>(__args)...);
515}
516
517template <class _ValueType>
518inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_THROW_BAD_ANY_CAST _ValueType any_cast(any const& __v) {
519  using _RawValueType = __remove_cvref_t<_ValueType>;
520  static_assert(is_constructible<_ValueType, _RawValueType const&>::value,
521                "ValueType is required to be a const lvalue reference "
522                "or a CopyConstructible type");
523  auto __tmp = std::any_cast<add_const_t<_RawValueType>>(&__v);
524  if (__tmp == nullptr)
525    __throw_bad_any_cast();
526  return static_cast<_ValueType>(*__tmp);
527}
528
529template <class _ValueType>
530inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_THROW_BAD_ANY_CAST _ValueType any_cast(any& __v) {
531  using _RawValueType = __remove_cvref_t<_ValueType>;
532  static_assert(is_constructible<_ValueType, _RawValueType&>::value,
533                "ValueType is required to be an lvalue reference "
534                "or a CopyConstructible type");
535  auto __tmp = std::any_cast<_RawValueType>(&__v);
536  if (__tmp == nullptr)
537    __throw_bad_any_cast();
538  return static_cast<_ValueType>(*__tmp);
539}
540
541template <class _ValueType>
542inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_THROW_BAD_ANY_CAST _ValueType any_cast(any&& __v) {
543  using _RawValueType = __remove_cvref_t<_ValueType>;
544  static_assert(is_constructible<_ValueType, _RawValueType>::value,
545                "ValueType is required to be an rvalue reference "
546                "or a CopyConstructible type");
547  auto __tmp = std::any_cast<_RawValueType>(&__v);
548  if (__tmp == nullptr)
549    __throw_bad_any_cast();
550  return static_cast<_ValueType>(std::move(*__tmp));
551}
552
553template <class _ValueType>
554inline _LIBCPP_HIDE_FROM_ABI add_pointer_t<add_const_t<_ValueType>> any_cast(any const* __any) _NOEXCEPT {
555  static_assert(!is_void_v<_ValueType>, "_ValueType may not be void.");
556  static_assert(!is_reference<_ValueType>::value, "_ValueType may not be a reference.");
557  return std::any_cast<_ValueType>(const_cast<any*>(__any));
558}
559
560template <class _RetType>
561inline _LIBCPP_HIDE_FROM_ABI _RetType __pointer_or_func_cast(void* __p, /*IsFunction*/ false_type) noexcept {
562  return static_cast<_RetType>(__p);
563}
564
565template <class _RetType>
566inline _LIBCPP_HIDE_FROM_ABI _RetType __pointer_or_func_cast(void*, /*IsFunction*/ true_type) noexcept {
567  return nullptr;
568}
569
570template <class _ValueType>
571_LIBCPP_HIDE_FROM_ABI add_pointer_t<_ValueType> any_cast(any* __any) _NOEXCEPT {
572  using __any_imp::_Action;
573  static_assert(!is_void_v<_ValueType>, "_ValueType may not be void.");
574  static_assert(!is_reference<_ValueType>::value, "_ValueType may not be a reference.");
575  typedef add_pointer_t<_ValueType> _ReturnType;
576  if (__any && __any->__h_) {
577    void* __p = __any->__call(
578        _Action::_Get,
579        nullptr,
580#  if _LIBCPP_HAS_RTTI
581        &typeid(_ValueType),
582#  else
583        nullptr,
584#  endif
585        __any_imp::__get_fallback_typeid<_ValueType>());
586    return std::__pointer_or_func_cast<_ReturnType>(__p, is_function<_ValueType>{});
587  }
588  return nullptr;
589}
590
591#endif // _LIBCPP_STD_VER >= 17
592
593_LIBCPP_END_NAMESPACE_STD
594
595_LIBCPP_POP_MACROS
596
597#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 17
598#  include <chrono>
599#endif
600
601#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
602#  include <atomic>
603#  include <concepts>
604#  include <cstdlib>
605#  include <iosfwd>
606#  include <iterator>
607#  include <memory>
608#  include <stdexcept>
609#  include <type_traits>
610#  include <variant>
611#endif
612
613#endif // _LIBCPP_ANY
614