Back to home page

EIC code displayed by LXR

 
 

    


Warning, /include/c++/v1/__cxx03/variant 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_VARIANT
0011 #define _LIBCPP___CXX03_VARIANT
0012 
0013 /*
0014    variant synopsis
0015 
0016 namespace std {
0017 
0018   // 20.7.2, class template variant
0019   template <class... Types>
0020   class variant {
0021   public:
0022 
0023     // 20.7.2.1, constructors
0024     constexpr variant() noexcept(see below);
0025     constexpr variant(const variant&);
0026     constexpr variant(variant&&) noexcept(see below);
0027 
0028     template <class T> constexpr variant(T&&) noexcept(see below);
0029 
0030     template <class T, class... Args>
0031     constexpr explicit variant(in_place_type_t<T>, Args&&...);
0032 
0033     template <class T, class U, class... Args>
0034     constexpr explicit variant(
0035         in_place_type_t<T>, initializer_list<U>, Args&&...);
0036 
0037     template <size_t I, class... Args>
0038     constexpr explicit variant(in_place_index_t<I>, Args&&...);
0039 
0040     template <size_t I, class U, class... Args>
0041     constexpr explicit variant(
0042         in_place_index_t<I>, initializer_list<U>, Args&&...);
0043 
0044     // 20.7.2.2, destructor
0045     constexpr ~variant();                                             // constexpr since c++20
0046 
0047     // 20.7.2.3, assignment
0048     constexpr variant& operator=(const variant&);
0049     constexpr variant& operator=(variant&&) noexcept(see below);
0050 
0051     template <class T>
0052     constexpr variant& operator=(T&&) noexcept(see below);            // constexpr since c++20
0053 
0054     // 20.7.2.4, modifiers
0055     template <class T, class... Args>
0056     constexpr T& emplace(Args&&...);                                  // constexpr since c++20
0057 
0058     template <class T, class U, class... Args>
0059     constexpr T& emplace(initializer_list<U>, Args&&...);             // constexpr since c++20
0060 
0061     template <size_t I, class... Args>
0062     constexpr variant_alternative_t<I, variant>& emplace(Args&&...);  // constexpr since c++20
0063 
0064     template <size_t I, class U, class...  Args>
0065     constexpr variant_alternative_t<I, variant>&
0066         emplace(initializer_list<U>, Args&&...);                      // constexpr since c++20
0067 
0068     // 20.7.2.5, value status
0069     constexpr bool valueless_by_exception() const noexcept;
0070     constexpr size_t index() const noexcept;
0071 
0072     // 20.7.2.6, swap
0073     void swap(variant&) noexcept(see below);
0074 
0075     // [variant.visit], visitation
0076     template<class Self, class Visitor>
0077       constexpr decltype(auto) visit(this Self&&, Visitor&&); // Since C++26
0078     template<class R, class Self, class Visitor>
0079       constexpr R visit(this Self&&, Visitor&&);              // Since C++26
0080   };
0081 
0082   // 20.7.3, variant helper classes
0083   template <class T> struct variant_size; // undefined
0084 
0085   template <class T>
0086   inline constexpr size_t variant_size_v = variant_size<T>::value;
0087 
0088   template <class T> struct variant_size<const T>;
0089   template <class T> struct variant_size<volatile T>;
0090   template <class T> struct variant_size<const volatile T>;
0091 
0092   template <class... Types>
0093   struct variant_size<variant<Types...>>;
0094 
0095   template <size_t I, class T> struct variant_alternative; // undefined
0096 
0097   template <size_t I, class T>
0098   using variant_alternative_t = typename variant_alternative<I, T>::type;
0099 
0100   template <size_t I, class T> struct variant_alternative<I, const T>;
0101   template <size_t I, class T> struct variant_alternative<I, volatile T>;
0102   template <size_t I, class T> struct variant_alternative<I, const volatile T>;
0103 
0104   template <size_t I, class... Types>
0105   struct variant_alternative<I, variant<Types...>>;
0106 
0107   inline constexpr size_t variant_npos = -1;
0108 
0109   // 20.7.4, value access
0110   template <class T, class... Types>
0111   constexpr bool holds_alternative(const variant<Types...>&) noexcept;
0112 
0113   template <size_t I, class... Types>
0114   constexpr variant_alternative_t<I, variant<Types...>>&
0115   get(variant<Types...>&);
0116 
0117   template <size_t I, class... Types>
0118   constexpr variant_alternative_t<I, variant<Types...>>&&
0119   get(variant<Types...>&&);
0120 
0121   template <size_t I, class... Types>
0122   constexpr variant_alternative_t<I, variant<Types...>> const&
0123   get(const variant<Types...>&);
0124 
0125   template <size_t I, class... Types>
0126   constexpr variant_alternative_t<I, variant<Types...>> const&&
0127   get(const variant<Types...>&&);
0128 
0129   template <class T, class...  Types>
0130   constexpr T& get(variant<Types...>&);
0131 
0132   template <class T, class... Types>
0133   constexpr T&& get(variant<Types...>&&);
0134 
0135   template <class T, class... Types>
0136   constexpr const T& get(const variant<Types...>&);
0137 
0138   template <class T, class... Types>
0139   constexpr const T&& get(const variant<Types...>&&);
0140 
0141   template <size_t I, class... Types>
0142   constexpr add_pointer_t<variant_alternative_t<I, variant<Types...>>>
0143   get_if(variant<Types...>*) noexcept;
0144 
0145   template <size_t I, class... Types>
0146   constexpr add_pointer_t<const variant_alternative_t<I, variant<Types...>>>
0147   get_if(const variant<Types...>*) noexcept;
0148 
0149   template <class T, class... Types>
0150   constexpr add_pointer_t<T>
0151   get_if(variant<Types...>*) noexcept;
0152 
0153   template <class T, class... Types>
0154   constexpr add_pointer_t<const T>
0155   get_if(const variant<Types...>*) noexcept;
0156 
0157   // 20.7.5, relational operators
0158   template <class... Types>
0159   constexpr bool operator==(const variant<Types...>&, const variant<Types...>&);
0160 
0161   template <class... Types>
0162   constexpr bool operator!=(const variant<Types...>&, const variant<Types...>&);
0163 
0164   template <class... Types>
0165   constexpr bool operator<(const variant<Types...>&, const variant<Types...>&);
0166 
0167   template <class... Types>
0168   constexpr bool operator>(const variant<Types...>&, const variant<Types...>&);
0169 
0170   template <class... Types>
0171   constexpr bool operator<=(const variant<Types...>&, const variant<Types...>&);
0172 
0173   template <class... Types>
0174   constexpr bool operator>=(const variant<Types...>&, const variant<Types...>&);
0175 
0176   template <class... Types> requires (three_way_comparable<Types> && ...)
0177   constexpr common_comparison_category_t<compare_three_way_result_t<Types>...>
0178     operator<=>(const variant<Types...>&, const variant<Types...>&);           // since C++20
0179 
0180   // 20.7.6, visitation
0181   template <class Visitor, class... Variants>
0182   constexpr see below visit(Visitor&&, Variants&&...);
0183 
0184   template <class R, class Visitor, class... Variants>
0185   constexpr R visit(Visitor&&, Variants&&...); // since C++20
0186 
0187   // 20.7.7, class monostate
0188   struct monostate;
0189 
0190   // 20.7.8, monostate relational operators
0191   constexpr bool operator==(monostate, monostate) noexcept;
0192   constexpr bool operator!=(monostate, monostate) noexcept;             // until C++20
0193   constexpr bool operator<(monostate, monostate) noexcept;              // until C++20
0194   constexpr bool operator>(monostate, monostate) noexcept;              // until C++20
0195   constexpr bool operator<=(monostate, monostate) noexcept;             // until C++20
0196   constexpr bool operator>=(monostate, monostate) noexcept;             // until C++20
0197   constexpr strong_ordering operator<=>(monostate, monostate) noexcept; // since C++20
0198 
0199   // 20.7.9, specialized algorithms
0200   template <class... Types>
0201   void swap(variant<Types...>&, variant<Types...>&) noexcept(see below);
0202 
0203   // 20.7.10, class bad_variant_access
0204   class bad_variant_access;
0205 
0206   // 20.7.11, hash support
0207   template <class T> struct hash;
0208   template <class... Types> struct hash<variant<Types...>>;
0209   template <> struct hash<monostate>;
0210 
0211 } // namespace std
0212 
0213 */
0214 
0215 #include <__cxx03/__compare/common_comparison_category.h>
0216 #include <__cxx03/__compare/compare_three_way_result.h>
0217 #include <__cxx03/__compare/three_way_comparable.h>
0218 #include <__cxx03/__config>
0219 #include <__cxx03/__exception/exception.h>
0220 #include <__cxx03/__functional/hash.h>
0221 #include <__cxx03/__functional/invoke.h>
0222 #include <__cxx03/__functional/operations.h>
0223 #include <__cxx03/__functional/unary_function.h>
0224 #include <__cxx03/__memory/addressof.h>
0225 #include <__cxx03/__memory/construct_at.h>
0226 #include <__cxx03/__tuple/find_index.h>
0227 #include <__cxx03/__tuple/sfinae_helpers.h>
0228 #include <__cxx03/__type_traits/add_const.h>
0229 #include <__cxx03/__type_traits/add_cv.h>
0230 #include <__cxx03/__type_traits/add_pointer.h>
0231 #include <__cxx03/__type_traits/add_volatile.h>
0232 #include <__cxx03/__type_traits/common_type.h>
0233 #include <__cxx03/__type_traits/conjunction.h>
0234 #include <__cxx03/__type_traits/dependent_type.h>
0235 #include <__cxx03/__type_traits/is_array.h>
0236 #include <__cxx03/__type_traits/is_constructible.h>
0237 #include <__cxx03/__type_traits/is_destructible.h>
0238 #include <__cxx03/__type_traits/is_nothrow_assignable.h>
0239 #include <__cxx03/__type_traits/is_nothrow_constructible.h>
0240 #include <__cxx03/__type_traits/is_reference.h>
0241 #include <__cxx03/__type_traits/is_trivially_assignable.h>
0242 #include <__cxx03/__type_traits/is_trivially_constructible.h>
0243 #include <__cxx03/__type_traits/is_trivially_destructible.h>
0244 #include <__cxx03/__type_traits/is_trivially_relocatable.h>
0245 #include <__cxx03/__type_traits/is_void.h>
0246 #include <__cxx03/__type_traits/remove_const.h>
0247 #include <__cxx03/__type_traits/remove_cvref.h>
0248 #include <__cxx03/__type_traits/type_identity.h>
0249 #include <__cxx03/__type_traits/void_t.h>
0250 #include <__cxx03/__utility/declval.h>
0251 #include <__cxx03/__utility/forward.h>
0252 #include <__cxx03/__utility/forward_like.h>
0253 #include <__cxx03/__utility/in_place.h>
0254 #include <__cxx03/__utility/integer_sequence.h>
0255 #include <__cxx03/__utility/move.h>
0256 #include <__cxx03/__utility/swap.h>
0257 #include <__cxx03/__variant/monostate.h>
0258 #include <__cxx03/__verbose_abort>
0259 #include <__cxx03/initializer_list>
0260 #include <__cxx03/limits>
0261 #include <__cxx03/new>
0262 #include <__cxx03/version>
0263 
0264 // standard-mandated includes
0265 
0266 // [variant.syn]
0267 #include <__cxx03/compare>
0268 
0269 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0270 #  pragma GCC system_header
0271 #endif
0272 
0273 _LIBCPP_PUSH_MACROS
0274 #include <__cxx03/__undef_macros>
0275 
0276 namespace std { // explicitly not using versioning namespace
0277 
0278 class _LIBCPP_EXPORTED_FROM_ABI _LIBCPP_AVAILABILITY_BAD_VARIANT_ACCESS bad_variant_access : public exception {
0279 public:
0280   const char* what() const _NOEXCEPT override;
0281 };
0282 
0283 } // namespace std
0284 
0285 _LIBCPP_BEGIN_NAMESPACE_STD
0286 
0287 #if _LIBCPP_STD_VER >= 17
0288 
0289 // Light N-dimensional array of function pointers. Used in place of std::array to avoid
0290 // adding a dependency.
0291 template <class _Tp, size_t _Size>
0292 struct __farray {
0293   static_assert(_Size > 0, "N-dimensional array should never be empty in std::visit");
0294   _Tp __buf_[_Size] = {};
0295 
0296   _LIBCPP_HIDE_FROM_ABI constexpr const _Tp& operator[](size_t __n) const noexcept { return __buf_[__n]; }
0297 };
0298 
0299 _LIBCPP_NORETURN inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS void
0300 __throw_bad_variant_access() {
0301 #  ifndef _LIBCPP_HAS_NO_EXCEPTIONS
0302   throw bad_variant_access();
0303 #  else
0304   _LIBCPP_VERBOSE_ABORT("bad_variant_access was thrown in -fno-exceptions mode");
0305 #  endif
0306 }
0307 
0308 template <class... _Types>
0309 class _LIBCPP_TEMPLATE_VIS variant;
0310 
0311 template <class _Tp>
0312 struct _LIBCPP_TEMPLATE_VIS variant_size;
0313 
0314 template <class _Tp>
0315 inline constexpr size_t variant_size_v = variant_size<_Tp>::value;
0316 
0317 template <class _Tp>
0318 struct _LIBCPP_TEMPLATE_VIS variant_size<const _Tp> : variant_size<_Tp> {};
0319 
0320 template <class _Tp>
0321 struct _LIBCPP_TEMPLATE_VIS variant_size<volatile _Tp> : variant_size<_Tp> {};
0322 
0323 template <class _Tp>
0324 struct _LIBCPP_TEMPLATE_VIS variant_size<const volatile _Tp> : variant_size<_Tp> {};
0325 
0326 template <class... _Types>
0327 struct _LIBCPP_TEMPLATE_VIS variant_size<variant<_Types...>> : integral_constant<size_t, sizeof...(_Types)> {};
0328 
0329 template <size_t _Ip, class _Tp>
0330 struct _LIBCPP_TEMPLATE_VIS variant_alternative;
0331 
0332 template <size_t _Ip, class _Tp>
0333 using variant_alternative_t = typename variant_alternative<_Ip, _Tp>::type;
0334 
0335 template <size_t _Ip, class _Tp>
0336 struct _LIBCPP_TEMPLATE_VIS variant_alternative<_Ip, const _Tp> : add_const<variant_alternative_t<_Ip, _Tp>> {};
0337 
0338 template <size_t _Ip, class _Tp>
0339 struct _LIBCPP_TEMPLATE_VIS variant_alternative<_Ip, volatile _Tp> : add_volatile<variant_alternative_t<_Ip, _Tp>> {};
0340 
0341 template <size_t _Ip, class _Tp>
0342 struct _LIBCPP_TEMPLATE_VIS variant_alternative<_Ip, const volatile _Tp> : add_cv<variant_alternative_t<_Ip, _Tp>> {};
0343 
0344 template <size_t _Ip, class... _Types>
0345 struct _LIBCPP_TEMPLATE_VIS variant_alternative<_Ip, variant<_Types...>> {
0346   static_assert(_Ip < sizeof...(_Types), "Index out of bounds in std::variant_alternative<>");
0347   using type = __type_pack_element<_Ip, _Types...>;
0348 };
0349 
0350 inline constexpr size_t variant_npos = static_cast<size_t>(-1);
0351 
0352 template <size_t _NumAlternatives>
0353 _LIBCPP_HIDE_FROM_ABI constexpr auto __choose_index_type() {
0354 #  ifdef _LIBCPP_ABI_VARIANT_INDEX_TYPE_OPTIMIZATION
0355   if constexpr (_NumAlternatives < numeric_limits<unsigned char>::max())
0356     return static_cast<unsigned char>(0);
0357   else if constexpr (_NumAlternatives < numeric_limits<unsigned short>::max())
0358     return static_cast<unsigned short>(0);
0359   else
0360 #  endif // _LIBCPP_ABI_VARIANT_INDEX_TYPE_OPTIMIZATION
0361     return static_cast<unsigned int>(0);
0362 }
0363 
0364 template <size_t _NumAlts>
0365 using __variant_index_t = decltype(std::__choose_index_type<_NumAlts>());
0366 
0367 template <class _IndexType>
0368 constexpr _IndexType __variant_npos = static_cast<_IndexType>(-1);
0369 
0370 template <class... _Types>
0371 class _LIBCPP_TEMPLATE_VIS variant;
0372 
0373 template <class... _Types>
0374 _LIBCPP_HIDE_FROM_ABI constexpr variant<_Types...>& __as_variant(variant<_Types...>& __vs) noexcept {
0375   return __vs;
0376 }
0377 
0378 template <class... _Types>
0379 _LIBCPP_HIDE_FROM_ABI constexpr const variant<_Types...>& __as_variant(const variant<_Types...>& __vs) noexcept {
0380   return __vs;
0381 }
0382 
0383 template <class... _Types>
0384 _LIBCPP_HIDE_FROM_ABI constexpr variant<_Types...>&& __as_variant(variant<_Types...>&& __vs) noexcept {
0385   return std::move(__vs);
0386 }
0387 
0388 template <class... _Types>
0389 _LIBCPP_HIDE_FROM_ABI constexpr const variant<_Types...>&& __as_variant(const variant<_Types...>&& __vs) noexcept {
0390   return std::move(__vs);
0391 }
0392 
0393 namespace __find_detail {
0394 
0395 template <class _Tp, class... _Types>
0396 _LIBCPP_HIDE_FROM_ABI constexpr size_t __find_index() {
0397   constexpr bool __matches[] = {is_same_v<_Tp, _Types>...};
0398   size_t __result            = __not_found;
0399   for (size_t __i = 0; __i < sizeof...(_Types); ++__i) {
0400     if (__matches[__i]) {
0401       if (__result != __not_found) {
0402         return __ambiguous;
0403       }
0404       __result = __i;
0405     }
0406   }
0407   return __result;
0408 }
0409 
0410 template <size_t _Index>
0411 struct __find_unambiguous_index_sfinae_impl : integral_constant<size_t, _Index> {};
0412 
0413 template <>
0414 struct __find_unambiguous_index_sfinae_impl<__not_found> {};
0415 
0416 template <>
0417 struct __find_unambiguous_index_sfinae_impl<__ambiguous> {};
0418 
0419 template <class _Tp, class... _Types>
0420 struct __find_unambiguous_index_sfinae : __find_unambiguous_index_sfinae_impl<__find_index<_Tp, _Types...>()> {};
0421 
0422 } // namespace __find_detail
0423 
0424 namespace __variant_detail {
0425 
0426 struct __valueless_t {};
0427 
0428 enum class _Trait { _TriviallyAvailable, _Available, _Unavailable };
0429 
0430 template <typename _Tp, template <typename> class _IsTriviallyAvailable, template <typename> class _IsAvailable>
0431 constexpr _Trait __trait =
0432     _IsTriviallyAvailable<_Tp>::value ? _Trait::_TriviallyAvailable
0433     : _IsAvailable<_Tp>::value
0434         ? _Trait::_Available
0435         : _Trait::_Unavailable;
0436 
0437 _LIBCPP_HIDE_FROM_ABI constexpr _Trait __common_trait(initializer_list<_Trait> __traits) {
0438   _Trait __result = _Trait::_TriviallyAvailable;
0439   for (_Trait __t : __traits) {
0440     if (static_cast<int>(__t) > static_cast<int>(__result)) {
0441       __result = __t;
0442     }
0443   }
0444   return __result;
0445 }
0446 
0447 template <typename... _Types>
0448 struct __traits {
0449   static constexpr _Trait __copy_constructible_trait =
0450       __variant_detail::__common_trait({__trait<_Types, is_trivially_copy_constructible, is_copy_constructible>...});
0451 
0452   static constexpr _Trait __move_constructible_trait =
0453       __variant_detail::__common_trait({__trait<_Types, is_trivially_move_constructible, is_move_constructible>...});
0454 
0455   static constexpr _Trait __copy_assignable_trait = __variant_detail::__common_trait(
0456       {__copy_constructible_trait, __trait<_Types, is_trivially_copy_assignable, is_copy_assignable>...});
0457 
0458   static constexpr _Trait __move_assignable_trait = __variant_detail::__common_trait(
0459       {__move_constructible_trait, __trait<_Types, is_trivially_move_assignable, is_move_assignable>...});
0460 
0461   static constexpr _Trait __destructible_trait =
0462       __variant_detail::__common_trait({__trait<_Types, is_trivially_destructible, is_destructible>...});
0463 };
0464 
0465 namespace __access {
0466 
0467 struct __union {
0468   template <class _Vp>
0469   _LIBCPP_HIDE_FROM_ABI static constexpr auto&& __get_alt(_Vp&& __v, in_place_index_t<0>) {
0470     return std::forward<_Vp>(__v).__head;
0471   }
0472 
0473   template <class _Vp, size_t _Ip>
0474   _LIBCPP_HIDE_FROM_ABI static constexpr auto&& __get_alt(_Vp&& __v, in_place_index_t<_Ip>) {
0475     return __get_alt(std::forward<_Vp>(__v).__tail, in_place_index<_Ip - 1>);
0476   }
0477 };
0478 
0479 struct __base {
0480   template <size_t _Ip, class _Vp>
0481   _LIBCPP_HIDE_FROM_ABI static constexpr auto&& __get_alt(_Vp&& __v) {
0482     return __union::__get_alt(std::forward<_Vp>(__v).__data, in_place_index<_Ip>);
0483   }
0484 };
0485 
0486 struct __variant {
0487   template <size_t _Ip, class _Vp>
0488   _LIBCPP_HIDE_FROM_ABI static constexpr auto&& __get_alt(_Vp&& __v) {
0489     return __base::__get_alt<_Ip>(std::forward<_Vp>(__v).__impl_);
0490   }
0491 };
0492 
0493 } // namespace __access
0494 
0495 namespace __visitation {
0496 
0497 struct __base {
0498   template <class _Visitor, class... _Vs>
0499   _LIBCPP_HIDE_FROM_ABI static constexpr decltype(auto)
0500   __visit_alt_at(size_t __index, _Visitor&& __visitor, _Vs&&... __vs) {
0501     constexpr auto __fdiagonal = __make_fdiagonal<_Visitor&&, decltype(std::forward<_Vs>(__vs).__as_base())...>();
0502     return __fdiagonal[__index](std::forward<_Visitor>(__visitor), std::forward<_Vs>(__vs).__as_base()...);
0503   }
0504 
0505   template <class _Visitor, class... _Vs>
0506   _LIBCPP_HIDE_FROM_ABI static constexpr decltype(auto) __visit_alt(_Visitor&& __visitor, _Vs&&... __vs) {
0507     constexpr auto __fmatrix = __make_fmatrix<_Visitor&&, decltype(std::forward<_Vs>(__vs).__as_base())...>();
0508     return __at(__fmatrix, __vs.index()...)(std::forward<_Visitor>(__visitor), std::forward<_Vs>(__vs).__as_base()...);
0509   }
0510 
0511 private:
0512   template <class _Tp>
0513   _LIBCPP_HIDE_FROM_ABI static constexpr const _Tp& __at(const _Tp& __elem) {
0514     return __elem;
0515   }
0516 
0517   template <class _Tp, size_t _Np, typename... _Indices>
0518   _LIBCPP_HIDE_FROM_ABI static constexpr auto&&
0519   __at(const __farray<_Tp, _Np>& __elems, size_t __index, _Indices... __indices) {
0520     return __at(__elems[__index], __indices...);
0521   }
0522 
0523   template <class _Fp, class... _Fs>
0524   static _LIBCPP_HIDE_FROM_ABI constexpr void __std_visit_visitor_return_type_check() {
0525     static_assert(
0526         __all<is_same_v<_Fp, _Fs>...>::value, "`std::visit` requires the visitor to have a single return type.");
0527   }
0528 
0529   template <class... _Fs>
0530   _LIBCPP_HIDE_FROM_ABI static constexpr auto __make_farray(_Fs&&... __fs) {
0531     __std_visit_visitor_return_type_check<__remove_cvref_t<_Fs>...>();
0532     using __result = __farray<common_type_t<__remove_cvref_t<_Fs>...>, sizeof...(_Fs)>;
0533     return __result{{std::forward<_Fs>(__fs)...}};
0534   }
0535 
0536   template <size_t... _Is>
0537   struct __dispatcher {
0538     template <class _Fp, class... _Vs>
0539     _LIBCPP_HIDE_FROM_ABI static constexpr decltype(auto) __dispatch(_Fp __f, _Vs... __vs) {
0540       return std::__invoke(static_cast<_Fp>(__f), __access::__base::__get_alt<_Is>(static_cast<_Vs>(__vs))...);
0541     }
0542   };
0543 
0544   template <class _Fp, class... _Vs, size_t... _Is>
0545   _LIBCPP_HIDE_FROM_ABI static constexpr auto __make_dispatch(index_sequence<_Is...>) {
0546     return __dispatcher<_Is...>::template __dispatch<_Fp, _Vs...>;
0547   }
0548 
0549   template <size_t _Ip, class _Fp, class... _Vs>
0550   _LIBCPP_HIDE_FROM_ABI static constexpr auto __make_fdiagonal_impl() {
0551     return __make_dispatch<_Fp, _Vs...>(index_sequence<((void)__type_identity<_Vs>{}, _Ip)...>{});
0552   }
0553 
0554   template <class _Fp, class... _Vs, size_t... _Is>
0555   _LIBCPP_HIDE_FROM_ABI static constexpr auto __make_fdiagonal_impl(index_sequence<_Is...>) {
0556     return __base::__make_farray(__make_fdiagonal_impl<_Is, _Fp, _Vs...>()...);
0557   }
0558 
0559   template <class _Fp, class _Vp, class... _Vs>
0560   _LIBCPP_HIDE_FROM_ABI static constexpr auto __make_fdiagonal() {
0561     constexpr size_t __np = __remove_cvref_t<_Vp>::__size();
0562     static_assert(__all<(__np == __remove_cvref_t<_Vs>::__size())...>::value);
0563     return __make_fdiagonal_impl<_Fp, _Vp, _Vs...>(make_index_sequence<__np>{});
0564   }
0565 
0566   template <class _Fp, class... _Vs, size_t... _Is>
0567   _LIBCPP_HIDE_FROM_ABI static constexpr auto __make_fmatrix_impl(index_sequence<_Is...> __is) {
0568     return __make_dispatch<_Fp, _Vs...>(__is);
0569   }
0570 
0571   template <class _Fp, class... _Vs, size_t... _Is, size_t... _Js, class... _Ls>
0572   _LIBCPP_HIDE_FROM_ABI static constexpr auto
0573   __make_fmatrix_impl(index_sequence<_Is...>, index_sequence<_Js...>, _Ls... __ls) {
0574     return __base::__make_farray(__make_fmatrix_impl<_Fp, _Vs...>(index_sequence<_Is..., _Js>{}, __ls...)...);
0575   }
0576 
0577   template <class _Fp, class... _Vs>
0578   _LIBCPP_HIDE_FROM_ABI static constexpr auto __make_fmatrix() {
0579     return __make_fmatrix_impl<_Fp, _Vs...>(
0580         index_sequence<>{}, make_index_sequence<__remove_cvref_t<_Vs>::__size()>{}...);
0581   }
0582 };
0583 
0584 struct __variant {
0585   template <class _Visitor, class... _Vs>
0586   _LIBCPP_HIDE_FROM_ABI static constexpr decltype(auto)
0587   __visit_alt_at(size_t __index, _Visitor&& __visitor, _Vs&&... __vs) {
0588     return __base::__visit_alt_at(__index, std::forward<_Visitor>(__visitor), std::forward<_Vs>(__vs).__impl_...);
0589   }
0590 
0591   template <class _Visitor, class... _Vs>
0592   _LIBCPP_HIDE_FROM_ABI static constexpr decltype(auto) __visit_alt(_Visitor&& __visitor, _Vs&&... __vs) {
0593     return __base::__visit_alt(
0594         std::forward<_Visitor>(__visitor), std::__as_variant(std::forward<_Vs>(__vs)).__impl_...);
0595   }
0596 
0597   template <class _Visitor, class... _Vs>
0598   _LIBCPP_HIDE_FROM_ABI static constexpr decltype(auto)
0599   __visit_value_at(size_t __index, _Visitor&& __visitor, _Vs&&... __vs) {
0600     return __visit_alt_at(__index, __make_value_visitor(std::forward<_Visitor>(__visitor)), std::forward<_Vs>(__vs)...);
0601   }
0602 
0603   template <class _Visitor, class... _Vs>
0604   _LIBCPP_HIDE_FROM_ABI static constexpr decltype(auto) __visit_value(_Visitor&& __visitor, _Vs&&... __vs) {
0605     return __visit_alt(__make_value_visitor(std::forward<_Visitor>(__visitor)), std::forward<_Vs>(__vs)...);
0606   }
0607 
0608 #  if _LIBCPP_STD_VER >= 20
0609   template <class _Rp, class _Visitor, class... _Vs>
0610   _LIBCPP_HIDE_FROM_ABI static constexpr _Rp __visit_value(_Visitor&& __visitor, _Vs&&... __vs) {
0611     return __visit_alt(__make_value_visitor<_Rp>(std::forward<_Visitor>(__visitor)), std::forward<_Vs>(__vs)...);
0612   }
0613 #  endif
0614 
0615 private:
0616   template <class _Visitor, class... _Values>
0617   static _LIBCPP_HIDE_FROM_ABI constexpr void __std_visit_exhaustive_visitor_check() {
0618     static_assert(is_invocable_v<_Visitor, _Values...>, "`std::visit` requires the visitor to be exhaustive.");
0619   }
0620 
0621   template <class _Visitor>
0622   struct __value_visitor {
0623     template <class... _Alts>
0624     _LIBCPP_HIDE_FROM_ABI constexpr decltype(auto) operator()(_Alts&&... __alts) const {
0625       __std_visit_exhaustive_visitor_check< _Visitor, decltype((std::forward<_Alts>(__alts).__value))...>();
0626       return std::__invoke(std::forward<_Visitor>(__visitor), std::forward<_Alts>(__alts).__value...);
0627     }
0628     _Visitor&& __visitor;
0629   };
0630 
0631 #  if _LIBCPP_STD_VER >= 20
0632   template <class _Rp, class _Visitor>
0633   struct __value_visitor_return_type {
0634     template <class... _Alts>
0635     _LIBCPP_HIDE_FROM_ABI constexpr _Rp operator()(_Alts&&... __alts) const {
0636       __std_visit_exhaustive_visitor_check< _Visitor, decltype((std::forward<_Alts>(__alts).__value))...>();
0637       if constexpr (is_void_v<_Rp>) {
0638         std::__invoke(std::forward<_Visitor>(__visitor), std::forward<_Alts>(__alts).__value...);
0639       } else {
0640         return std::__invoke(std::forward<_Visitor>(__visitor), std::forward<_Alts>(__alts).__value...);
0641       }
0642     }
0643 
0644     _Visitor&& __visitor;
0645   };
0646 #  endif
0647 
0648   template <class _Visitor>
0649   _LIBCPP_HIDE_FROM_ABI static constexpr auto __make_value_visitor(_Visitor&& __visitor) {
0650     return __value_visitor<_Visitor>{std::forward<_Visitor>(__visitor)};
0651   }
0652 
0653 #  if _LIBCPP_STD_VER >= 20
0654   template <class _Rp, class _Visitor>
0655   _LIBCPP_HIDE_FROM_ABI static constexpr auto __make_value_visitor(_Visitor&& __visitor) {
0656     return __value_visitor_return_type<_Rp, _Visitor>{std::forward<_Visitor>(__visitor)};
0657   }
0658 #  endif
0659 };
0660 
0661 } // namespace __visitation
0662 
0663 // Adding semi-colons in macro expansions helps clang-format to do a better job.
0664 // This macro is used to avoid compilation errors due to "stray" semi-colons.
0665 #  define _LIBCPP_EAT_SEMICOLON static_assert(true, "")
0666 
0667 template <size_t _Index, class _Tp>
0668 struct _LIBCPP_TEMPLATE_VIS __alt {
0669   using __value_type              = _Tp;
0670   static constexpr size_t __index = _Index;
0671 
0672   template <class... _Args>
0673   _LIBCPP_HIDE_FROM_ABI explicit constexpr __alt(in_place_t, _Args&&... __args)
0674       : __value(std::forward<_Args>(__args)...) {}
0675 
0676   __value_type __value;
0677 };
0678 
0679 template <_Trait _DestructibleTrait, size_t _Index, class... _Types>
0680 union _LIBCPP_TEMPLATE_VIS __union;
0681 
0682 template <_Trait _DestructibleTrait, size_t _Index>
0683 union _LIBCPP_TEMPLATE_VIS __union<_DestructibleTrait, _Index> {};
0684 
0685 #  define _LIBCPP_VARIANT_UNION(destructible_trait, destructor_definition)                                             \
0686     template <size_t _Index, class _Tp, class... _Types>                                                               \
0687     union _LIBCPP_TEMPLATE_VIS __union<destructible_trait, _Index, _Tp, _Types...> {                                   \
0688     public:                                                                                                            \
0689       _LIBCPP_HIDE_FROM_ABI explicit constexpr __union(__valueless_t) noexcept : __dummy{} {}                          \
0690                                                                                                                        \
0691       template <class... _Args>                                                                                        \
0692       _LIBCPP_HIDE_FROM_ABI explicit constexpr __union(in_place_index_t<0>, _Args&&... __args)                         \
0693           : __head(in_place, std::forward<_Args>(__args)...) {}                                                        \
0694                                                                                                                        \
0695       template <size_t _Ip, class... _Args>                                                                            \
0696       _LIBCPP_HIDE_FROM_ABI explicit constexpr __union(in_place_index_t<_Ip>, _Args&&... __args)                       \
0697           : __tail(in_place_index<_Ip - 1>, std::forward<_Args>(__args)...) {}                                         \
0698                                                                                                                        \
0699       _LIBCPP_HIDE_FROM_ABI __union(const __union&)            = default;                                              \
0700       _LIBCPP_HIDE_FROM_ABI __union(__union&&)                 = default;                                              \
0701       _LIBCPP_HIDE_FROM_ABI __union& operator=(const __union&) = default;                                              \
0702       _LIBCPP_HIDE_FROM_ABI __union& operator=(__union&&)      = default;                                              \
0703       destructor_definition;                                                                                           \
0704                                                                                                                        \
0705     private:                                                                                                           \
0706       char __dummy;                                                                                                    \
0707       __alt<_Index, _Tp> __head;                                                                                       \
0708       __union<destructible_trait, _Index + 1, _Types...> __tail;                                                       \
0709                                                                                                                        \
0710       friend struct __access::__union;                                                                                 \
0711     }
0712 
0713 _LIBCPP_VARIANT_UNION(_Trait::_TriviallyAvailable,
0714                       _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 ~__union() = default);
0715 _LIBCPP_VARIANT_UNION(
0716     _Trait::_Available, _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 ~__union() {} _LIBCPP_EAT_SEMICOLON);
0717 _LIBCPP_VARIANT_UNION(_Trait::_Unavailable, _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 ~__union() = delete);
0718 
0719 #  undef _LIBCPP_VARIANT_UNION
0720 
0721 template <_Trait _DestructibleTrait, class... _Types>
0722 class _LIBCPP_TEMPLATE_VIS __base {
0723 public:
0724   using __index_t = __variant_index_t<sizeof...(_Types)>;
0725 
0726   _LIBCPP_HIDE_FROM_ABI explicit constexpr __base(__valueless_t __tag) noexcept
0727       : __data(__tag), __index(__variant_npos<__index_t>) {}
0728 
0729   template <size_t _Ip, class... _Args>
0730   _LIBCPP_HIDE_FROM_ABI explicit constexpr __base(in_place_index_t<_Ip>, _Args&&... __args)
0731       : __data(in_place_index<_Ip>, std::forward<_Args>(__args)...), __index(_Ip) {}
0732 
0733   _LIBCPP_HIDE_FROM_ABI constexpr bool valueless_by_exception() const noexcept { return index() == variant_npos; }
0734 
0735   _LIBCPP_HIDE_FROM_ABI constexpr size_t index() const noexcept {
0736     return __index == __variant_npos<__index_t> ? variant_npos : __index;
0737   }
0738 
0739 protected:
0740   _LIBCPP_HIDE_FROM_ABI constexpr auto&& __as_base() & { return *this; }
0741 
0742   _LIBCPP_HIDE_FROM_ABI constexpr auto&& __as_base() && { return std::move(*this); }
0743 
0744   _LIBCPP_HIDE_FROM_ABI constexpr auto&& __as_base() const& { return *this; }
0745 
0746   _LIBCPP_HIDE_FROM_ABI constexpr auto&& __as_base() const&& { return std::move(*this); }
0747 
0748   _LIBCPP_HIDE_FROM_ABI static constexpr size_t __size() { return sizeof...(_Types); }
0749 
0750   __union<_DestructibleTrait, 0, _Types...> __data;
0751   __index_t __index;
0752 
0753   friend struct __access::__base;
0754   friend struct __visitation::__base;
0755 };
0756 
0757 template <class _Traits, _Trait = _Traits::__destructible_trait>
0758 class _LIBCPP_TEMPLATE_VIS __dtor;
0759 
0760 #  define _LIBCPP_VARIANT_DESTRUCTOR(destructible_trait, destructor_definition, destroy)                               \
0761     template <class... _Types>                                                                                         \
0762     class _LIBCPP_TEMPLATE_VIS __dtor<__traits<_Types...>, destructible_trait>                                         \
0763         : public __base<destructible_trait, _Types...> {                                                               \
0764       using __base_type = __base<destructible_trait, _Types...>;                                                       \
0765       using __index_t   = typename __base_type::__index_t;                                                             \
0766                                                                                                                        \
0767     public:                                                                                                            \
0768       using __base_type::__base_type;                                                                                  \
0769       using __base_type::operator=;                                                                                    \
0770       _LIBCPP_HIDE_FROM_ABI __dtor(const __dtor&)            = default;                                                \
0771       _LIBCPP_HIDE_FROM_ABI __dtor(__dtor&&)                 = default;                                                \
0772       _LIBCPP_HIDE_FROM_ABI __dtor& operator=(const __dtor&) = default;                                                \
0773       _LIBCPP_HIDE_FROM_ABI __dtor& operator=(__dtor&&)      = default;                                                \
0774       destructor_definition;                                                                                           \
0775                                                                                                                        \
0776     protected:                                                                                                         \
0777       destroy;                                                                                                         \
0778     }
0779 
0780 _LIBCPP_VARIANT_DESTRUCTOR(
0781     _Trait::_TriviallyAvailable,
0782     _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 ~__dtor() = default,
0783     _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __destroy() noexcept {
0784       this->__index = __variant_npos<__index_t>;
0785     } _LIBCPP_EAT_SEMICOLON);
0786 
0787 _LIBCPP_VARIANT_DESTRUCTOR(
0788     _Trait::_Available,
0789     _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 ~__dtor() { __destroy(); } _LIBCPP_EAT_SEMICOLON,
0790     _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __destroy() noexcept {
0791       if (!this->valueless_by_exception()) {
0792         __visitation::__base::__visit_alt(
0793             [](auto& __alt) noexcept {
0794               using __alt_type = __remove_cvref_t<decltype(__alt)>;
0795               __alt.~__alt_type();
0796             },
0797             *this);
0798       }
0799       this->__index = __variant_npos<__index_t>;
0800     } _LIBCPP_EAT_SEMICOLON);
0801 
0802 _LIBCPP_VARIANT_DESTRUCTOR(_Trait::_Unavailable,
0803                            _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 ~__dtor()                 = delete,
0804                            _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __destroy() noexcept = delete);
0805 
0806 #  undef _LIBCPP_VARIANT_DESTRUCTOR
0807 
0808 template <class _Traits>
0809 class _LIBCPP_TEMPLATE_VIS __ctor : public __dtor<_Traits> {
0810   using __base_type = __dtor<_Traits>;
0811 
0812 public:
0813   using __base_type::__base_type;
0814   using __base_type::operator=;
0815 
0816 protected:
0817   template <class _Rhs>
0818   _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR_SINCE_CXX20 void __generic_construct(__ctor& __lhs, _Rhs&& __rhs) {
0819     __lhs.__destroy();
0820     if (!__rhs.valueless_by_exception()) {
0821       auto __rhs_index = __rhs.index();
0822       __visitation::__base::__visit_alt_at(
0823           __rhs_index,
0824           [&__lhs](auto&& __rhs_alt) {
0825             std::__construct_at(std::addressof(__lhs.__data),
0826                                 in_place_index<__decay_t<decltype(__rhs_alt)>::__index>,
0827                                 std::forward<decltype(__rhs_alt)>(__rhs_alt).__value);
0828           },
0829           std::forward<_Rhs>(__rhs));
0830       __lhs.__index = __rhs_index;
0831     }
0832   }
0833 };
0834 
0835 template <class _Traits, _Trait = _Traits::__move_constructible_trait>
0836 class _LIBCPP_TEMPLATE_VIS __move_constructor;
0837 
0838 #  define _LIBCPP_VARIANT_MOVE_CONSTRUCTOR(move_constructible_trait, move_constructor_definition)                      \
0839     template <class... _Types>                                                                                         \
0840     class _LIBCPP_TEMPLATE_VIS __move_constructor<__traits<_Types...>, move_constructible_trait>                       \
0841         : public __ctor<__traits<_Types...>> {                                                                         \
0842       using __base_type = __ctor<__traits<_Types...>>;                                                                 \
0843                                                                                                                        \
0844     public:                                                                                                            \
0845       using __base_type::__base_type;                                                                                  \
0846       using __base_type::operator=;                                                                                    \
0847                                                                                                                        \
0848       _LIBCPP_HIDE_FROM_ABI __move_constructor(const __move_constructor&)            = default;                        \
0849       _LIBCPP_HIDE_FROM_ABI ~__move_constructor()                                    = default;                        \
0850       _LIBCPP_HIDE_FROM_ABI __move_constructor& operator=(const __move_constructor&) = default;                        \
0851       _LIBCPP_HIDE_FROM_ABI __move_constructor& operator=(__move_constructor&&)      = default;                        \
0852       move_constructor_definition;                                                                                     \
0853     }
0854 
0855 _LIBCPP_VARIANT_MOVE_CONSTRUCTOR(
0856     _Trait::_TriviallyAvailable,
0857     _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __move_constructor(__move_constructor&& __that) = default);
0858 
0859 _LIBCPP_VARIANT_MOVE_CONSTRUCTOR(
0860     _Trait::_Available,
0861     _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __move_constructor(__move_constructor&& __that) noexcept(
0862         __all<is_nothrow_move_constructible_v<_Types>...>::value)
0863     : __move_constructor(__valueless_t{}) {
0864       this->__generic_construct(*this, std::move(__that));
0865     } _LIBCPP_EAT_SEMICOLON);
0866 
0867 _LIBCPP_VARIANT_MOVE_CONSTRUCTOR(
0868     _Trait::_Unavailable,
0869     _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __move_constructor(__move_constructor&&) = delete);
0870 
0871 #  undef _LIBCPP_VARIANT_MOVE_CONSTRUCTOR
0872 
0873 template <class _Traits, _Trait = _Traits::__copy_constructible_trait>
0874 class _LIBCPP_TEMPLATE_VIS __copy_constructor;
0875 
0876 #  define _LIBCPP_VARIANT_COPY_CONSTRUCTOR(copy_constructible_trait, copy_constructor_definition)                      \
0877     template <class... _Types>                                                                                         \
0878     class _LIBCPP_TEMPLATE_VIS __copy_constructor<__traits<_Types...>, copy_constructible_trait>                       \
0879         : public __move_constructor<__traits<_Types...>> {                                                             \
0880       using __base_type = __move_constructor<__traits<_Types...>>;                                                     \
0881                                                                                                                        \
0882     public:                                                                                                            \
0883       using __base_type::__base_type;                                                                                  \
0884       using __base_type::operator=;                                                                                    \
0885                                                                                                                        \
0886       _LIBCPP_HIDE_FROM_ABI __copy_constructor(__copy_constructor&&)                 = default;                        \
0887       _LIBCPP_HIDE_FROM_ABI ~__copy_constructor()                                    = default;                        \
0888       _LIBCPP_HIDE_FROM_ABI __copy_constructor& operator=(const __copy_constructor&) = default;                        \
0889       _LIBCPP_HIDE_FROM_ABI __copy_constructor& operator=(__copy_constructor&&)      = default;                        \
0890       copy_constructor_definition;                                                                                     \
0891     }
0892 
0893 _LIBCPP_VARIANT_COPY_CONSTRUCTOR(
0894     _Trait::_TriviallyAvailable,
0895     _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __copy_constructor(const __copy_constructor& __that) = default);
0896 
0897 _LIBCPP_VARIANT_COPY_CONSTRUCTOR(
0898     _Trait::_Available,
0899     _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __copy_constructor(const __copy_constructor& __that)
0900     : __copy_constructor(__valueless_t{}) { this->__generic_construct(*this, __that); } _LIBCPP_EAT_SEMICOLON);
0901 
0902 _LIBCPP_VARIANT_COPY_CONSTRUCTOR(
0903     _Trait::_Unavailable,
0904     _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __copy_constructor(const __copy_constructor&) = delete);
0905 
0906 #  undef _LIBCPP_VARIANT_COPY_CONSTRUCTOR
0907 
0908 template <class _Traits>
0909 class _LIBCPP_TEMPLATE_VIS __assignment : public __copy_constructor<_Traits> {
0910   using __base_type = __copy_constructor<_Traits>;
0911 
0912 public:
0913   using __base_type::__base_type;
0914   using __base_type::operator=;
0915 
0916   template <size_t _Ip, class... _Args>
0917   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 auto& __emplace(_Args&&... __args) {
0918     this->__destroy();
0919     std::__construct_at(std::addressof(this->__data), in_place_index<_Ip>, std::forward<_Args>(__args)...);
0920     this->__index = _Ip;
0921     return __access::__base::__get_alt<_Ip>(*this).__value;
0922   }
0923 
0924 protected:
0925   template <size_t _Ip, class _Tp, class _Arg>
0926   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __assign_alt(__alt<_Ip, _Tp>& __a, _Arg&& __arg) {
0927     if (this->index() == _Ip) {
0928       __a.__value = std::forward<_Arg>(__arg);
0929     } else {
0930       struct {
0931         _LIBCPP_HIDDEN _LIBCPP_CONSTEXPR_SINCE_CXX20 void operator()(true_type) const {
0932           __this->__emplace<_Ip>(std::forward<_Arg>(__arg));
0933         }
0934         _LIBCPP_HIDDEN _LIBCPP_CONSTEXPR_SINCE_CXX20 void operator()(false_type) const {
0935           __this->__emplace<_Ip>(_Tp(std::forward<_Arg>(__arg)));
0936         }
0937         __assignment* __this;
0938         _Arg&& __arg;
0939       } __impl{this, std::forward<_Arg>(__arg)};
0940       __impl(bool_constant < is_nothrow_constructible_v<_Tp, _Arg> || !is_nothrow_move_constructible_v < _Tp >> {});
0941     }
0942   }
0943 
0944   template <class _That>
0945   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __generic_assign(_That&& __that) {
0946     if (this->valueless_by_exception() && __that.valueless_by_exception()) {
0947       // do nothing.
0948     } else if (__that.valueless_by_exception()) {
0949       this->__destroy();
0950     } else {
0951       __visitation::__base::__visit_alt_at(
0952           __that.index(),
0953           [this](auto& __this_alt, auto&& __that_alt) {
0954             this->__assign_alt(__this_alt, std::forward<decltype(__that_alt)>(__that_alt).__value);
0955           },
0956           *this,
0957           std::forward<_That>(__that));
0958     }
0959   }
0960 };
0961 
0962 template <class _Traits, _Trait = _Traits::__move_assignable_trait>
0963 class _LIBCPP_TEMPLATE_VIS __move_assignment;
0964 
0965 #  define _LIBCPP_VARIANT_MOVE_ASSIGNMENT(move_assignable_trait, move_assignment_definition)                           \
0966     template <class... _Types>                                                                                         \
0967     class _LIBCPP_TEMPLATE_VIS __move_assignment<__traits<_Types...>, move_assignable_trait>                           \
0968         : public __assignment<__traits<_Types...>> {                                                                   \
0969       using __base_type = __assignment<__traits<_Types...>>;                                                           \
0970                                                                                                                        \
0971     public:                                                                                                            \
0972       using __base_type::__base_type;                                                                                  \
0973       using __base_type::operator=;                                                                                    \
0974                                                                                                                        \
0975       _LIBCPP_HIDE_FROM_ABI __move_assignment(const __move_assignment&)            = default;                          \
0976       _LIBCPP_HIDE_FROM_ABI __move_assignment(__move_assignment&&)                 = default;                          \
0977       _LIBCPP_HIDE_FROM_ABI ~__move_assignment()                                   = default;                          \
0978       _LIBCPP_HIDE_FROM_ABI __move_assignment& operator=(const __move_assignment&) = default;                          \
0979       move_assignment_definition;                                                                                      \
0980     }
0981 
0982 _LIBCPP_VARIANT_MOVE_ASSIGNMENT(_Trait::_TriviallyAvailable,
0983                                 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __move_assignment& operator=(
0984                                     __move_assignment&& __that) = default);
0985 
0986 _LIBCPP_VARIANT_MOVE_ASSIGNMENT(
0987     _Trait::_Available,
0988     _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __move_assignment&
0989     operator=(__move_assignment&& __that) noexcept(
0990         __all<(is_nothrow_move_constructible_v<_Types> && is_nothrow_move_assignable_v<_Types>)...>::value) {
0991       this->__generic_assign(std::move(__that));
0992       return *this;
0993     } _LIBCPP_EAT_SEMICOLON);
0994 
0995 _LIBCPP_VARIANT_MOVE_ASSIGNMENT(
0996     _Trait::_Unavailable,
0997     _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __move_assignment& operator=(__move_assignment&&) = delete);
0998 
0999 #  undef _LIBCPP_VARIANT_MOVE_ASSIGNMENT
1000 
1001 template <class _Traits, _Trait = _Traits::__copy_assignable_trait>
1002 class _LIBCPP_TEMPLATE_VIS __copy_assignment;
1003 
1004 #  define _LIBCPP_VARIANT_COPY_ASSIGNMENT(copy_assignable_trait, copy_assignment_definition)                           \
1005     template <class... _Types>                                                                                         \
1006     class _LIBCPP_TEMPLATE_VIS __copy_assignment<__traits<_Types...>, copy_assignable_trait>                           \
1007         : public __move_assignment<__traits<_Types...>> {                                                              \
1008       using __base_type = __move_assignment<__traits<_Types...>>;                                                      \
1009                                                                                                                        \
1010     public:                                                                                                            \
1011       using __base_type::__base_type;                                                                                  \
1012       using __base_type::operator=;                                                                                    \
1013                                                                                                                        \
1014       _LIBCPP_HIDE_FROM_ABI __copy_assignment(const __copy_assignment&)       = default;                               \
1015       _LIBCPP_HIDE_FROM_ABI __copy_assignment(__copy_assignment&&)            = default;                               \
1016       _LIBCPP_HIDE_FROM_ABI ~__copy_assignment()                              = default;                               \
1017       _LIBCPP_HIDE_FROM_ABI __copy_assignment& operator=(__copy_assignment&&) = default;                               \
1018       copy_assignment_definition;                                                                                      \
1019     }
1020 
1021 _LIBCPP_VARIANT_COPY_ASSIGNMENT(_Trait::_TriviallyAvailable,
1022                                 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __copy_assignment& operator=(
1023                                     const __copy_assignment& __that) = default);
1024 
1025 _LIBCPP_VARIANT_COPY_ASSIGNMENT(
1026     _Trait::_Available,
1027     _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __copy_assignment&
1028     operator=(const __copy_assignment& __that) {
1029       this->__generic_assign(__that);
1030       return *this;
1031     } _LIBCPP_EAT_SEMICOLON);
1032 
1033 _LIBCPP_VARIANT_COPY_ASSIGNMENT(_Trait::_Unavailable,
1034                                 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __copy_assignment& operator=(
1035                                     const __copy_assignment&) = delete);
1036 
1037 #  undef _LIBCPP_VARIANT_COPY_ASSIGNMENT
1038 
1039 template <class... _Types>
1040 class _LIBCPP_TEMPLATE_VIS __impl : public __copy_assignment<__traits<_Types...>> {
1041   using __base_type = __copy_assignment<__traits<_Types...>>;
1042 
1043 public:
1044   using __base_type::__base_type; // get in_place_index_t constructor & friends
1045   _LIBCPP_HIDE_FROM_ABI __impl(__impl const&)            = default;
1046   _LIBCPP_HIDE_FROM_ABI __impl(__impl&&)                 = default;
1047   _LIBCPP_HIDE_FROM_ABI __impl& operator=(__impl const&) = default;
1048   _LIBCPP_HIDE_FROM_ABI __impl& operator=(__impl&&)      = default;
1049 
1050   template <size_t _Ip, class _Arg>
1051   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __assign(_Arg&& __arg) {
1052     this->__assign_alt(__access::__base::__get_alt<_Ip>(*this), std::forward<_Arg>(__arg));
1053   }
1054 
1055   inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __swap(__impl& __that) {
1056     if (this->valueless_by_exception() && __that.valueless_by_exception()) {
1057       // do nothing.
1058     } else if (this->index() == __that.index()) {
1059       __visitation::__base::__visit_alt_at(
1060           this->index(),
1061           [](auto& __this_alt, auto& __that_alt) {
1062             using std::swap;
1063             swap(__this_alt.__value, __that_alt.__value);
1064           },
1065           *this,
1066           __that);
1067     } else {
1068       __impl* __lhs = this;
1069       __impl* __rhs = std::addressof(__that);
1070       if (__lhs->__move_nothrow() && !__rhs->__move_nothrow()) {
1071         std::swap(__lhs, __rhs);
1072       }
1073       __impl __tmp(std::move(*__rhs));
1074 #  ifndef _LIBCPP_HAS_NO_EXCEPTIONS
1075       if constexpr (__all<is_nothrow_move_constructible_v<_Types>...>::value) {
1076         this->__generic_construct(*__rhs, std::move(*__lhs));
1077       } else {
1078         // EXTENSION: When the move construction of `__lhs` into `__rhs` throws
1079         // and `__tmp` is nothrow move constructible then we move `__tmp` back
1080         // into `__rhs` and provide the strong exception safety guarantee.
1081         try {
1082           this->__generic_construct(*__rhs, std::move(*__lhs));
1083         } catch (...) {
1084           if (__tmp.__move_nothrow()) {
1085             this->__generic_construct(*__rhs, std::move(__tmp));
1086           }
1087           throw;
1088         }
1089       }
1090 #  else
1091       // this isn't consolidated with the `if constexpr` branch above due to
1092       // `throw` being ill-formed with exceptions disabled even when discarded.
1093       this->__generic_construct(*__rhs, std::move(*__lhs));
1094 #  endif
1095       this->__generic_construct(*__lhs, std::move(__tmp));
1096     }
1097   }
1098 
1099 private:
1100   constexpr inline _LIBCPP_HIDE_FROM_ABI bool __move_nothrow() const {
1101     constexpr bool __results[] = {is_nothrow_move_constructible_v<_Types>...};
1102     return this->valueless_by_exception() || __results[this->index()];
1103   }
1104 };
1105 
1106 struct __no_narrowing_check {
1107   template <class _Dest, class _Source>
1108   using _Apply = __type_identity<_Dest>;
1109 };
1110 
1111 struct __narrowing_check {
1112   template <class _Dest>
1113   static auto __test_impl(_Dest (&&)[1]) -> __type_identity<_Dest>;
1114   template <class _Dest, class _Source>
1115   using _Apply _LIBCPP_NODEBUG = decltype(__test_impl<_Dest>({std::declval<_Source>()}));
1116 };
1117 
1118 template <class _Dest, class _Source>
1119 using __check_for_narrowing _LIBCPP_NODEBUG =
1120     typename _If< is_arithmetic<_Dest>::value, __narrowing_check, __no_narrowing_check >::template _Apply<_Dest,
1121                                                                                                           _Source>;
1122 
1123 template <class _Tp, size_t _Idx>
1124 struct __overload {
1125   template <class _Up>
1126   auto operator()(_Tp, _Up&&) const -> __check_for_narrowing<_Tp, _Up>;
1127 };
1128 
1129 template <class... _Bases>
1130 struct __all_overloads : _Bases... {
1131   void operator()() const;
1132   using _Bases::operator()...;
1133 };
1134 
1135 template <class _IdxSeq>
1136 struct __make_overloads_imp;
1137 
1138 template <size_t... _Idx>
1139 struct __make_overloads_imp<__tuple_indices<_Idx...> > {
1140   template <class... _Types>
1141   using _Apply _LIBCPP_NODEBUG = __all_overloads<__overload<_Types, _Idx>...>;
1142 };
1143 
1144 template <class... _Types>
1145 using _MakeOverloads _LIBCPP_NODEBUG =
1146     typename __make_overloads_imp< __make_indices_imp<sizeof...(_Types), 0> >::template _Apply<_Types...>;
1147 
1148 template <class _Tp, class... _Types>
1149 using __best_match_t = typename invoke_result_t<_MakeOverloads<_Types...>, _Tp, _Tp>::type;
1150 
1151 } // namespace __variant_detail
1152 
1153 template <class _Visitor, class... _Vs, typename = void_t<decltype(std::__as_variant(std::declval<_Vs>()))...>>
1154 _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS constexpr decltype(auto)
1155 visit(_Visitor&& __visitor, _Vs&&... __vs);
1156 
1157 #  if _LIBCPP_STD_VER >= 20
1158 template <class _Rp,
1159           class _Visitor,
1160           class... _Vs,
1161           typename = void_t<decltype(std::__as_variant(std::declval<_Vs>()))...>>
1162 _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS constexpr _Rp
1163 visit(_Visitor&& __visitor, _Vs&&... __vs);
1164 #  endif
1165 
1166 template <class... _Types>
1167 class _LIBCPP_TEMPLATE_VIS _LIBCPP_DECLSPEC_EMPTY_BASES variant
1168     : private __sfinae_ctor_base< __all<is_copy_constructible_v<_Types>...>::value,
1169                                   __all<is_move_constructible_v<_Types>...>::value>,
1170       private __sfinae_assign_base<
1171           __all<(is_copy_constructible_v<_Types> && is_copy_assignable_v<_Types>)...>::value,
1172           __all<(is_move_constructible_v<_Types> && is_move_assignable_v<_Types>)...>::value> {
1173   static_assert(0 < sizeof...(_Types), "variant must consist of at least one alternative.");
1174 
1175   static_assert(__all<!is_array_v<_Types>...>::value, "variant can not have an array type as an alternative.");
1176 
1177   static_assert(__all<!is_reference_v<_Types>...>::value, "variant can not have a reference type as an alternative.");
1178 
1179   static_assert(__all<!is_void_v<_Types>...>::value, "variant can not have a void type as an alternative.");
1180 
1181   using __first_type = variant_alternative_t<0, variant>;
1182 
1183 public:
1184   using __trivially_relocatable =
1185       conditional_t<_And<__libcpp_is_trivially_relocatable<_Types>...>::value, variant, void>;
1186 
1187   template <bool _Dummy                                                                               = true,
1188             enable_if_t<__dependent_type<is_default_constructible<__first_type>, _Dummy>::value, int> = 0>
1189   _LIBCPP_HIDE_FROM_ABI constexpr variant() noexcept(is_nothrow_default_constructible_v<__first_type>)
1190       : __impl_(in_place_index<0>) {}
1191 
1192   _LIBCPP_HIDE_FROM_ABI constexpr variant(const variant&) = default;
1193   _LIBCPP_HIDE_FROM_ABI constexpr variant(variant&&)      = default;
1194 
1195   template < class _Arg,
1196              enable_if_t<!is_same_v<__remove_cvref_t<_Arg>, variant>, int>        = 0,
1197              enable_if_t<!__is_inplace_type<__remove_cvref_t<_Arg>>::value, int>  = 0,
1198              enable_if_t<!__is_inplace_index<__remove_cvref_t<_Arg>>::value, int> = 0,
1199              class _Tp  = __variant_detail::__best_match_t<_Arg, _Types...>,
1200              size_t _Ip = __find_detail::__find_unambiguous_index_sfinae<_Tp, _Types...>::value,
1201              enable_if_t<is_constructible_v<_Tp, _Arg>, int> = 0>
1202   _LIBCPP_HIDE_FROM_ABI constexpr variant(_Arg&& __arg) noexcept(is_nothrow_constructible_v<_Tp, _Arg>)
1203       : __impl_(in_place_index<_Ip>, std::forward<_Arg>(__arg)) {}
1204 
1205   template <size_t _Ip,
1206             class... _Args,
1207             class                                               = enable_if_t<(_Ip < sizeof...(_Types)), int>,
1208             class _Tp                                           = variant_alternative_t<_Ip, variant<_Types...>>,
1209             enable_if_t<is_constructible_v<_Tp, _Args...>, int> = 0>
1210   _LIBCPP_HIDE_FROM_ABI explicit constexpr variant(in_place_index_t<_Ip>, _Args&&... __args) noexcept(
1211       is_nothrow_constructible_v<_Tp, _Args...>)
1212       : __impl_(in_place_index<_Ip>, std::forward<_Args>(__args)...) {}
1213 
1214   template < size_t _Ip,
1215              class _Up,
1216              class... _Args,
1217              enable_if_t<(_Ip < sizeof...(_Types)), int> = 0,
1218              class _Tp                                   = variant_alternative_t<_Ip, variant<_Types...>>,
1219              enable_if_t<is_constructible_v<_Tp, initializer_list<_Up>&, _Args...>, int> = 0>
1220   _LIBCPP_HIDE_FROM_ABI explicit constexpr variant(
1221       in_place_index_t<_Ip>,
1222       initializer_list<_Up> __il,
1223       _Args&&... __args) noexcept(is_nothrow_constructible_v<_Tp, initializer_list<_Up>&, _Args...>)
1224       : __impl_(in_place_index<_Ip>, __il, std::forward<_Args>(__args)...) {}
1225 
1226   template < class _Tp,
1227              class... _Args,
1228              size_t _Ip = __find_detail::__find_unambiguous_index_sfinae<_Tp, _Types...>::value,
1229              enable_if_t<is_constructible_v<_Tp, _Args...>, int> = 0>
1230   _LIBCPP_HIDE_FROM_ABI explicit constexpr variant(in_place_type_t<_Tp>, _Args&&... __args) noexcept(
1231       is_nothrow_constructible_v<_Tp, _Args...>)
1232       : __impl_(in_place_index<_Ip>, std::forward<_Args>(__args)...) {}
1233 
1234   template < class _Tp,
1235              class _Up,
1236              class... _Args,
1237              size_t _Ip = __find_detail::__find_unambiguous_index_sfinae<_Tp, _Types...>::value,
1238              enable_if_t<is_constructible_v<_Tp, initializer_list<_Up>&, _Args...>, int> = 0>
1239   _LIBCPP_HIDE_FROM_ABI explicit constexpr variant(
1240       in_place_type_t<_Tp>,
1241       initializer_list<_Up> __il,
1242       _Args&&... __args) noexcept(is_nothrow_constructible_v<_Tp, initializer_list< _Up>&, _Args...>)
1243       : __impl_(in_place_index<_Ip>, __il, std::forward<_Args>(__args)...) {}
1244 
1245   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 ~variant() = default;
1246 
1247   _LIBCPP_HIDE_FROM_ABI constexpr variant& operator=(const variant&) = default;
1248   _LIBCPP_HIDE_FROM_ABI constexpr variant& operator=(variant&&)      = default;
1249 
1250   template < class _Arg,
1251              enable_if_t<!is_same_v<__remove_cvref_t<_Arg>, variant>, int> = 0,
1252              class _Tp  = __variant_detail::__best_match_t<_Arg, _Types...>,
1253              size_t _Ip = __find_detail::__find_unambiguous_index_sfinae<_Tp, _Types...>::value,
1254              enable_if_t<is_assignable_v<_Tp&, _Arg> && is_constructible_v<_Tp, _Arg>, int> = 0>
1255   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 variant&
1256   operator=(_Arg&& __arg) noexcept(is_nothrow_assignable_v<_Tp&, _Arg> && is_nothrow_constructible_v<_Tp, _Arg>) {
1257     __impl_.template __assign<_Ip>(std::forward<_Arg>(__arg));
1258     return *this;
1259   }
1260 
1261   template < size_t _Ip,
1262              class... _Args,
1263              enable_if_t<(_Ip < sizeof...(_Types)), int>         = 0,
1264              class _Tp                                           = variant_alternative_t<_Ip, variant<_Types...>>,
1265              enable_if_t<is_constructible_v<_Tp, _Args...>, int> = 0>
1266   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Tp& emplace(_Args&&... __args) {
1267     return __impl_.template __emplace<_Ip>(std::forward<_Args>(__args)...);
1268   }
1269 
1270   template < size_t _Ip,
1271              class _Up,
1272              class... _Args,
1273              enable_if_t<(_Ip < sizeof...(_Types)), int> = 0,
1274              class _Tp                                   = variant_alternative_t<_Ip, variant<_Types...>>,
1275              enable_if_t<is_constructible_v<_Tp, initializer_list<_Up>&, _Args...>, int> = 0>
1276   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Tp& emplace(initializer_list<_Up> __il, _Args&&... __args) {
1277     return __impl_.template __emplace<_Ip>(__il, std::forward<_Args>(__args)...);
1278   }
1279 
1280   template < class _Tp,
1281              class... _Args,
1282              size_t _Ip = __find_detail::__find_unambiguous_index_sfinae<_Tp, _Types...>::value,
1283              enable_if_t<is_constructible_v<_Tp, _Args...>, int> = 0>
1284   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Tp& emplace(_Args&&... __args) {
1285     return __impl_.template __emplace<_Ip>(std::forward<_Args>(__args)...);
1286   }
1287 
1288   template < class _Tp,
1289              class _Up,
1290              class... _Args,
1291              size_t _Ip = __find_detail::__find_unambiguous_index_sfinae<_Tp, _Types...>::value,
1292              enable_if_t<is_constructible_v<_Tp, initializer_list<_Up>&, _Args...>, int> = 0>
1293   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Tp& emplace(initializer_list<_Up> __il, _Args&&... __args) {
1294     return __impl_.template __emplace<_Ip>(__il, std::forward<_Args>(__args)...);
1295   }
1296 
1297   _LIBCPP_HIDE_FROM_ABI constexpr bool valueless_by_exception() const noexcept {
1298     return __impl_.valueless_by_exception();
1299   }
1300 
1301   _LIBCPP_HIDE_FROM_ABI constexpr size_t index() const noexcept { return __impl_.index(); }
1302 
1303   template < bool _Dummy       = true,
1304              enable_if_t< __all<(__dependent_type<is_move_constructible<_Types>, _Dummy>::value &&
1305                                  __dependent_type<is_swappable<_Types>, _Dummy>::value)...>::value,
1306                           int> = 0>
1307   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void swap(variant& __that) noexcept(
1308       __all<(is_nothrow_move_constructible_v<_Types> && is_nothrow_swappable_v<_Types>)...>::value) {
1309     __impl_.__swap(__that.__impl_);
1310   }
1311 
1312 #  if _LIBCPP_STD_VER >= 26 && defined(_LIBCPP_HAS_EXPLICIT_THIS_PARAMETER)
1313   // Helper class to implement [variant.visit]/10
1314   //   Constraints: The call to visit does not use an explicit template-argument-list
1315   //   that begins with a type template-argument.
1316   struct __variant_visit_barrier_tag {
1317     _LIBCPP_HIDE_FROM_ABI explicit __variant_visit_barrier_tag() = default;
1318   };
1319 
1320   template <__variant_visit_barrier_tag = __variant_visit_barrier_tag{}, class _Self, class _Visitor>
1321   _LIBCPP_HIDE_FROM_ABI constexpr decltype(auto) visit(this _Self&& __self, _Visitor&& __visitor) {
1322     using _VariantT = _OverrideRef<_Self&&, _CopyConst<remove_reference_t<_Self>, variant>>;
1323     return std::visit(std::forward<_Visitor>(__visitor), (_VariantT)__self);
1324   }
1325 
1326   template <class _Rp, class _Self, class _Visitor>
1327   _LIBCPP_HIDE_FROM_ABI constexpr _Rp visit(this _Self&& __self, _Visitor&& __visitor) {
1328     using _VariantT = _OverrideRef<_Self&&, _CopyConst<remove_reference_t<_Self>, variant>>;
1329     return std::visit<_Rp>(std::forward<_Visitor>(__visitor), (_VariantT)__self);
1330   }
1331 #  endif
1332 
1333 private:
1334   __variant_detail::__impl<_Types...> __impl_;
1335 
1336   friend struct __variant_detail::__access::__variant;
1337   friend struct __variant_detail::__visitation::__variant;
1338 };
1339 
1340 template <size_t _Ip, class... _Types>
1341 _LIBCPP_HIDE_FROM_ABI constexpr bool __holds_alternative(const variant<_Types...>& __v) noexcept {
1342   return __v.index() == _Ip;
1343 }
1344 
1345 template <class _Tp, class... _Types>
1346 _LIBCPP_HIDE_FROM_ABI constexpr bool holds_alternative(const variant<_Types...>& __v) noexcept {
1347   return std::__holds_alternative<__find_exactly_one_t<_Tp, _Types...>::value>(__v);
1348 }
1349 
1350 template <size_t _Ip, class _Vp>
1351 _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS constexpr auto&& __generic_get(_Vp&& __v) {
1352   using __variant_detail::__access::__variant;
1353   if (!std::__holds_alternative<_Ip>(__v)) {
1354     __throw_bad_variant_access();
1355   }
1356   return __variant::__get_alt<_Ip>(std::forward<_Vp>(__v)).__value;
1357 }
1358 
1359 template <size_t _Ip, class... _Types>
1360 _LIBCPP_HIDE_FROM_ABI
1361 _LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS constexpr variant_alternative_t<_Ip, variant<_Types...>>&
1362 get(variant<_Types...>& __v) {
1363   static_assert(_Ip < sizeof...(_Types));
1364   static_assert(!is_void_v<variant_alternative_t<_Ip, variant<_Types...>>>);
1365   return std::__generic_get<_Ip>(__v);
1366 }
1367 
1368 template <size_t _Ip, class... _Types>
1369 _LIBCPP_HIDE_FROM_ABI
1370 _LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS constexpr variant_alternative_t<_Ip, variant<_Types...>>&&
1371 get(variant<_Types...>&& __v) {
1372   static_assert(_Ip < sizeof...(_Types));
1373   static_assert(!is_void_v<variant_alternative_t<_Ip, variant<_Types...>>>);
1374   return std::__generic_get<_Ip>(std::move(__v));
1375 }
1376 
1377 template <size_t _Ip, class... _Types>
1378 _LIBCPP_HIDE_FROM_ABI
1379 _LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS constexpr const variant_alternative_t<_Ip, variant<_Types...>>&
1380 get(const variant<_Types...>& __v) {
1381   static_assert(_Ip < sizeof...(_Types));
1382   static_assert(!is_void_v<variant_alternative_t<_Ip, variant<_Types...>>>);
1383   return std::__generic_get<_Ip>(__v);
1384 }
1385 
1386 template <size_t _Ip, class... _Types>
1387 _LIBCPP_HIDE_FROM_ABI
1388 _LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS constexpr const variant_alternative_t<_Ip, variant<_Types...>>&&
1389 get(const variant<_Types...>&& __v) {
1390   static_assert(_Ip < sizeof...(_Types));
1391   static_assert(!is_void_v<variant_alternative_t<_Ip, variant<_Types...>>>);
1392   return std::__generic_get<_Ip>(std::move(__v));
1393 }
1394 
1395 template <class _Tp, class... _Types>
1396 _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS constexpr _Tp& get(variant<_Types...>& __v) {
1397   static_assert(!is_void_v<_Tp>);
1398   return std::get<__find_exactly_one_t<_Tp, _Types...>::value>(__v);
1399 }
1400 
1401 template <class _Tp, class... _Types>
1402 _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS constexpr _Tp&& get(variant<_Types...>&& __v) {
1403   static_assert(!is_void_v<_Tp>);
1404   return std::get<__find_exactly_one_t<_Tp, _Types...>::value>(std::move(__v));
1405 }
1406 
1407 template <class _Tp, class... _Types>
1408 _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS constexpr const _Tp&
1409 get(const variant<_Types...>& __v) {
1410   static_assert(!is_void_v<_Tp>);
1411   return std::get<__find_exactly_one_t<_Tp, _Types...>::value>(__v);
1412 }
1413 
1414 template <class _Tp, class... _Types>
1415 _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS constexpr const _Tp&&
1416 get(const variant<_Types...>&& __v) {
1417   static_assert(!is_void_v<_Tp>);
1418   return std::get<__find_exactly_one_t<_Tp, _Types...>::value>(std::move(__v));
1419 }
1420 
1421 template <size_t _Ip, class _Vp>
1422 _LIBCPP_HIDE_FROM_ABI constexpr auto* __generic_get_if(_Vp* __v) noexcept {
1423   using __variant_detail::__access::__variant;
1424   return __v && std::__holds_alternative<_Ip>(*__v) ? std::addressof(__variant::__get_alt<_Ip>(*__v).__value) : nullptr;
1425 }
1426 
1427 template <size_t _Ip, class... _Types>
1428 _LIBCPP_HIDE_FROM_ABI constexpr add_pointer_t<variant_alternative_t<_Ip, variant<_Types...>>>
1429 get_if(variant<_Types...>* __v) noexcept {
1430   static_assert(_Ip < sizeof...(_Types));
1431   static_assert(!is_void_v<variant_alternative_t<_Ip, variant<_Types...>>>);
1432   return std::__generic_get_if<_Ip>(__v);
1433 }
1434 
1435 template <size_t _Ip, class... _Types>
1436 _LIBCPP_HIDE_FROM_ABI constexpr add_pointer_t<const variant_alternative_t<_Ip, variant<_Types...>>>
1437 get_if(const variant<_Types...>* __v) noexcept {
1438   static_assert(_Ip < sizeof...(_Types));
1439   static_assert(!is_void_v<variant_alternative_t<_Ip, variant<_Types...>>>);
1440   return std::__generic_get_if<_Ip>(__v);
1441 }
1442 
1443 template <class _Tp, class... _Types>
1444 _LIBCPP_HIDE_FROM_ABI constexpr add_pointer_t<_Tp> get_if(variant<_Types...>* __v) noexcept {
1445   static_assert(!is_void_v<_Tp>);
1446   return std::get_if<__find_exactly_one_t<_Tp, _Types...>::value>(__v);
1447 }
1448 
1449 template <class _Tp, class... _Types>
1450 _LIBCPP_HIDE_FROM_ABI constexpr add_pointer_t<const _Tp> get_if(const variant<_Types...>* __v) noexcept {
1451   static_assert(!is_void_v<_Tp>);
1452   return std::get_if<__find_exactly_one_t<_Tp, _Types...>::value>(__v);
1453 }
1454 
1455 template <class _Operator>
1456 struct __convert_to_bool {
1457   template <class _T1, class _T2>
1458   _LIBCPP_HIDE_FROM_ABI constexpr bool operator()(_T1&& __t1, _T2&& __t2) const {
1459     static_assert(is_convertible<decltype(_Operator{}(std::forward<_T1>(__t1), std::forward<_T2>(__t2))), bool>::value,
1460                   "the relational operator does not return a type which is implicitly convertible to bool");
1461     return _Operator{}(std::forward<_T1>(__t1), std::forward<_T2>(__t2));
1462   }
1463 };
1464 
1465 template <class... _Types>
1466 _LIBCPP_HIDE_FROM_ABI constexpr bool operator==(const variant<_Types...>& __lhs, const variant<_Types...>& __rhs) {
1467   using __variant_detail::__visitation::__variant;
1468   if (__lhs.index() != __rhs.index())
1469     return false;
1470   if (__lhs.valueless_by_exception())
1471     return true;
1472   return __variant::__visit_value_at(__lhs.index(), __convert_to_bool<equal_to<>>{}, __lhs, __rhs);
1473 }
1474 
1475 #  if _LIBCPP_STD_VER >= 20
1476 
1477 template <class... _Types>
1478   requires(three_way_comparable<_Types> && ...)
1479 _LIBCPP_HIDE_FROM_ABI constexpr common_comparison_category_t<compare_three_way_result_t<_Types>...>
1480 operator<=>(const variant<_Types...>& __lhs, const variant<_Types...>& __rhs) {
1481   using __variant_detail::__visitation::__variant;
1482   using __result_t = common_comparison_category_t<compare_three_way_result_t<_Types>...>;
1483   if (__lhs.valueless_by_exception() && __rhs.valueless_by_exception())
1484     return strong_ordering::equal;
1485   if (__lhs.valueless_by_exception())
1486     return strong_ordering::less;
1487   if (__rhs.valueless_by_exception())
1488     return strong_ordering::greater;
1489   if (auto __c = __lhs.index() <=> __rhs.index(); __c != 0)
1490     return __c;
1491   auto __three_way = []<class _Type>(const _Type& __v, const _Type& __w) -> __result_t { return __v <=> __w; };
1492   return __variant::__visit_value_at(__lhs.index(), __three_way, __lhs, __rhs);
1493 }
1494 
1495 #  endif // _LIBCPP_STD_VER >= 20
1496 
1497 template <class... _Types>
1498 _LIBCPP_HIDE_FROM_ABI constexpr bool operator!=(const variant<_Types...>& __lhs, const variant<_Types...>& __rhs) {
1499   using __variant_detail::__visitation::__variant;
1500   if (__lhs.index() != __rhs.index())
1501     return true;
1502   if (__lhs.valueless_by_exception())
1503     return false;
1504   return __variant::__visit_value_at(__lhs.index(), __convert_to_bool<not_equal_to<>>{}, __lhs, __rhs);
1505 }
1506 
1507 template <class... _Types>
1508 _LIBCPP_HIDE_FROM_ABI constexpr bool operator<(const variant<_Types...>& __lhs, const variant<_Types...>& __rhs) {
1509   using __variant_detail::__visitation::__variant;
1510   if (__rhs.valueless_by_exception())
1511     return false;
1512   if (__lhs.valueless_by_exception())
1513     return true;
1514   if (__lhs.index() < __rhs.index())
1515     return true;
1516   if (__lhs.index() > __rhs.index())
1517     return false;
1518   return __variant::__visit_value_at(__lhs.index(), __convert_to_bool<less<>>{}, __lhs, __rhs);
1519 }
1520 
1521 template <class... _Types>
1522 _LIBCPP_HIDE_FROM_ABI constexpr bool operator>(const variant<_Types...>& __lhs, const variant<_Types...>& __rhs) {
1523   using __variant_detail::__visitation::__variant;
1524   if (__lhs.valueless_by_exception())
1525     return false;
1526   if (__rhs.valueless_by_exception())
1527     return true;
1528   if (__lhs.index() > __rhs.index())
1529     return true;
1530   if (__lhs.index() < __rhs.index())
1531     return false;
1532   return __variant::__visit_value_at(__lhs.index(), __convert_to_bool<greater<>>{}, __lhs, __rhs);
1533 }
1534 
1535 template <class... _Types>
1536 _LIBCPP_HIDE_FROM_ABI constexpr bool operator<=(const variant<_Types...>& __lhs, const variant<_Types...>& __rhs) {
1537   using __variant_detail::__visitation::__variant;
1538   if (__lhs.valueless_by_exception())
1539     return true;
1540   if (__rhs.valueless_by_exception())
1541     return false;
1542   if (__lhs.index() < __rhs.index())
1543     return true;
1544   if (__lhs.index() > __rhs.index())
1545     return false;
1546   return __variant::__visit_value_at(__lhs.index(), __convert_to_bool<less_equal<>>{}, __lhs, __rhs);
1547 }
1548 
1549 template <class... _Types>
1550 _LIBCPP_HIDE_FROM_ABI constexpr bool operator>=(const variant<_Types...>& __lhs, const variant<_Types...>& __rhs) {
1551   using __variant_detail::__visitation::__variant;
1552   if (__rhs.valueless_by_exception())
1553     return true;
1554   if (__lhs.valueless_by_exception())
1555     return false;
1556   if (__lhs.index() > __rhs.index())
1557     return true;
1558   if (__lhs.index() < __rhs.index())
1559     return false;
1560   return __variant::__visit_value_at(__lhs.index(), __convert_to_bool<greater_equal<>>{}, __lhs, __rhs);
1561 }
1562 
1563 template <class... _Vs>
1564 _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS constexpr void __throw_if_valueless(_Vs&&... __vs) {
1565   const bool __valueless = (... || std::__as_variant(__vs).valueless_by_exception());
1566   if (__valueless) {
1567     __throw_bad_variant_access();
1568   }
1569 }
1570 
1571 template < class _Visitor, class... _Vs, typename>
1572 _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS constexpr decltype(auto)
1573 visit(_Visitor&& __visitor, _Vs&&... __vs) {
1574   using __variant_detail::__visitation::__variant;
1575   std::__throw_if_valueless(std::forward<_Vs>(__vs)...);
1576   return __variant::__visit_value(std::forward<_Visitor>(__visitor), std::forward<_Vs>(__vs)...);
1577 }
1578 
1579 #  if _LIBCPP_STD_VER >= 20
1580 template < class _Rp, class _Visitor, class... _Vs, typename>
1581 _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS constexpr _Rp
1582 visit(_Visitor&& __visitor, _Vs&&... __vs) {
1583   using __variant_detail::__visitation::__variant;
1584   std::__throw_if_valueless(std::forward<_Vs>(__vs)...);
1585   return __variant::__visit_value<_Rp>(std::forward<_Visitor>(__visitor), std::forward<_Vs>(__vs)...);
1586 }
1587 #  endif
1588 
1589 template <class... _Types>
1590 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 auto
1591 swap(variant<_Types...>& __lhs,
1592      variant<_Types...>& __rhs) noexcept(noexcept(__lhs.swap(__rhs))) -> decltype(__lhs.swap(__rhs)) {
1593   return __lhs.swap(__rhs);
1594 }
1595 
1596 template <class... _Types>
1597 struct _LIBCPP_TEMPLATE_VIS hash< __enable_hash_helper<variant<_Types...>, remove_const_t<_Types>...>> {
1598   using argument_type = variant<_Types...>;
1599   using result_type   = size_t;
1600 
1601   _LIBCPP_HIDE_FROM_ABI result_type operator()(const argument_type& __v) const {
1602     using __variant_detail::__visitation::__variant;
1603     size_t __res =
1604         __v.valueless_by_exception()
1605             ? 299792458 // Random value chosen by the universe upon creation
1606             : __variant::__visit_alt(
1607                   [](const auto& __alt) {
1608                     using __alt_type   = __remove_cvref_t<decltype(__alt)>;
1609                     using __value_type = remove_const_t< typename __alt_type::__value_type>;
1610                     return hash<__value_type>{}(__alt.__value);
1611                   },
1612                   __v);
1613     return std::__hash_combine(__res, hash<size_t>{}(__v.index()));
1614   }
1615 };
1616 
1617 // __unchecked_get is the same as std::get, except, it is UB to use it with the wrong
1618 // type whereas std::get will throw or returning nullptr. This makes it faster than
1619 // std::get.
1620 template <size_t _Ip, class _Vp>
1621 _LIBCPP_HIDE_FROM_ABI constexpr auto&& __unchecked_get(_Vp&& __v) noexcept {
1622   using __variant_detail::__access::__variant;
1623   return __variant::__get_alt<_Ip>(std::forward<_Vp>(__v)).__value;
1624 }
1625 
1626 template <class _Tp, class... _Types>
1627 _LIBCPP_HIDE_FROM_ABI constexpr auto&& __unchecked_get(const variant<_Types...>& __v) noexcept {
1628   return std::__unchecked_get<__find_exactly_one_t<_Tp, _Types...>::value>(__v);
1629 }
1630 
1631 template <class _Tp, class... _Types>
1632 _LIBCPP_HIDE_FROM_ABI constexpr auto&& __unchecked_get(variant<_Types...>& __v) noexcept {
1633   return std::__unchecked_get<__find_exactly_one_t<_Tp, _Types...>::value>(__v);
1634 }
1635 
1636 #endif // _LIBCPP_STD_VER >= 17
1637 
1638 _LIBCPP_END_NAMESPACE_STD
1639 
1640 _LIBCPP_POP_MACROS
1641 
1642 #if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
1643 #  include <__cxx03/exception>
1644 #  include <__cxx03/tuple>
1645 #  include <__cxx03/type_traits>
1646 #  include <__cxx03/typeinfo>
1647 #  include <__cxx03/utility>
1648 #endif
1649 
1650 #endif // _LIBCPP___CXX03_VARIANT