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