xref: /aosp_15_r20/external/libcxx/include/variant (revision 58b9f456b02922dfdb1fad8a988d5fd8765ecb80)
1*58b9f456SAndroid Build Coastguard Worker// -*- C++ -*-
2*58b9f456SAndroid Build Coastguard Worker//===------------------------------ variant -------------------------------===//
3*58b9f456SAndroid Build Coastguard Worker//
4*58b9f456SAndroid Build Coastguard Worker//                     The LLVM Compiler Infrastructure
5*58b9f456SAndroid Build Coastguard Worker//
6*58b9f456SAndroid Build Coastguard Worker// This file is dual licensed under the MIT and the University of Illinois Open
7*58b9f456SAndroid Build Coastguard Worker// Source Licenses. See LICENSE.TXT for details.
8*58b9f456SAndroid Build Coastguard Worker//
9*58b9f456SAndroid Build Coastguard Worker//===----------------------------------------------------------------------===//
10*58b9f456SAndroid Build Coastguard Worker
11*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP_VARIANT
12*58b9f456SAndroid Build Coastguard Worker#define _LIBCPP_VARIANT
13*58b9f456SAndroid Build Coastguard Worker
14*58b9f456SAndroid Build Coastguard Worker/*
15*58b9f456SAndroid Build Coastguard Worker   variant synopsis
16*58b9f456SAndroid Build Coastguard Worker
17*58b9f456SAndroid Build Coastguard Workernamespace std {
18*58b9f456SAndroid Build Coastguard Worker
19*58b9f456SAndroid Build Coastguard Worker  // 20.7.2, class template variant
20*58b9f456SAndroid Build Coastguard Worker  template <class... Types>
21*58b9f456SAndroid Build Coastguard Worker  class variant {
22*58b9f456SAndroid Build Coastguard Worker  public:
23*58b9f456SAndroid Build Coastguard Worker
24*58b9f456SAndroid Build Coastguard Worker    // 20.7.2.1, constructors
25*58b9f456SAndroid Build Coastguard Worker    constexpr variant() noexcept(see below);
26*58b9f456SAndroid Build Coastguard Worker    variant(const variant&);                // constexpr in C++20
27*58b9f456SAndroid Build Coastguard Worker    variant(variant&&) noexcept(see below); // constexpr in C++20
28*58b9f456SAndroid Build Coastguard Worker
29*58b9f456SAndroid Build Coastguard Worker    template <class T> constexpr variant(T&&) noexcept(see below);
30*58b9f456SAndroid Build Coastguard Worker
31*58b9f456SAndroid Build Coastguard Worker    template <class T, class... Args>
32*58b9f456SAndroid Build Coastguard Worker    constexpr explicit variant(in_place_type_t<T>, Args&&...);
33*58b9f456SAndroid Build Coastguard Worker
34*58b9f456SAndroid Build Coastguard Worker    template <class T, class U, class... Args>
35*58b9f456SAndroid Build Coastguard Worker    constexpr explicit variant(
36*58b9f456SAndroid Build Coastguard Worker        in_place_type_t<T>, initializer_list<U>, Args&&...);
37*58b9f456SAndroid Build Coastguard Worker
38*58b9f456SAndroid Build Coastguard Worker    template <size_t I, class... Args>
39*58b9f456SAndroid Build Coastguard Worker    constexpr explicit variant(in_place_index_t<I>, Args&&...);
40*58b9f456SAndroid Build Coastguard Worker
41*58b9f456SAndroid Build Coastguard Worker    template <size_t I, class U, class... Args>
42*58b9f456SAndroid Build Coastguard Worker    constexpr explicit variant(
43*58b9f456SAndroid Build Coastguard Worker        in_place_index_t<I>, initializer_list<U>, Args&&...);
44*58b9f456SAndroid Build Coastguard Worker
45*58b9f456SAndroid Build Coastguard Worker    // 20.7.2.2, destructor
46*58b9f456SAndroid Build Coastguard Worker    ~variant();
47*58b9f456SAndroid Build Coastguard Worker
48*58b9f456SAndroid Build Coastguard Worker    // 20.7.2.3, assignment
49*58b9f456SAndroid Build Coastguard Worker    variant& operator=(const variant&);                // constexpr in C++20
50*58b9f456SAndroid Build Coastguard Worker    variant& operator=(variant&&) noexcept(see below); // constexpr in C++20
51*58b9f456SAndroid Build Coastguard Worker
52*58b9f456SAndroid Build Coastguard Worker    template <class T> variant& operator=(T&&) noexcept(see below);
53*58b9f456SAndroid Build Coastguard Worker
54*58b9f456SAndroid Build Coastguard Worker    // 20.7.2.4, modifiers
55*58b9f456SAndroid Build Coastguard Worker    template <class T, class... Args>
56*58b9f456SAndroid Build Coastguard Worker    T& emplace(Args&&...);
57*58b9f456SAndroid Build Coastguard Worker
58*58b9f456SAndroid Build Coastguard Worker    template <class T, class U, class... Args>
59*58b9f456SAndroid Build Coastguard Worker    T& emplace(initializer_list<U>, Args&&...);
60*58b9f456SAndroid Build Coastguard Worker
61*58b9f456SAndroid Build Coastguard Worker    template <size_t I, class... Args>
62*58b9f456SAndroid Build Coastguard Worker    variant_alternative_t<I, variant>& emplace(Args&&...);
63*58b9f456SAndroid Build Coastguard Worker
64*58b9f456SAndroid Build Coastguard Worker    template <size_t I, class U, class...  Args>
65*58b9f456SAndroid Build Coastguard Worker    variant_alternative_t<I, variant>& emplace(initializer_list<U>, Args&&...);
66*58b9f456SAndroid Build Coastguard Worker
67*58b9f456SAndroid Build Coastguard Worker    // 20.7.2.5, value status
68*58b9f456SAndroid Build Coastguard Worker    constexpr bool valueless_by_exception() const noexcept;
69*58b9f456SAndroid Build Coastguard Worker    constexpr size_t index() const noexcept;
70*58b9f456SAndroid Build Coastguard Worker
71*58b9f456SAndroid Build Coastguard Worker    // 20.7.2.6, swap
72*58b9f456SAndroid Build Coastguard Worker    void swap(variant&) noexcept(see below);
73*58b9f456SAndroid Build Coastguard Worker  };
74*58b9f456SAndroid Build Coastguard Worker
75*58b9f456SAndroid Build Coastguard Worker  // 20.7.3, variant helper classes
76*58b9f456SAndroid Build Coastguard Worker  template <class T> struct variant_size; // undefined
77*58b9f456SAndroid Build Coastguard Worker
78*58b9f456SAndroid Build Coastguard Worker  template <class T>
79*58b9f456SAndroid Build Coastguard Worker  inline constexpr size_t variant_size_v = variant_size<T>::value;
80*58b9f456SAndroid Build Coastguard Worker
81*58b9f456SAndroid Build Coastguard Worker  template <class T> struct variant_size<const T>;
82*58b9f456SAndroid Build Coastguard Worker  template <class T> struct variant_size<volatile T>;
83*58b9f456SAndroid Build Coastguard Worker  template <class T> struct variant_size<const volatile T>;
84*58b9f456SAndroid Build Coastguard Worker
85*58b9f456SAndroid Build Coastguard Worker  template <class... Types>
86*58b9f456SAndroid Build Coastguard Worker  struct variant_size<variant<Types...>>;
87*58b9f456SAndroid Build Coastguard Worker
88*58b9f456SAndroid Build Coastguard Worker  template <size_t I, class T> struct variant_alternative; // undefined
89*58b9f456SAndroid Build Coastguard Worker
90*58b9f456SAndroid Build Coastguard Worker  template <size_t I, class T>
91*58b9f456SAndroid Build Coastguard Worker  using variant_alternative_t = typename variant_alternative<I, T>::type;
92*58b9f456SAndroid Build Coastguard Worker
93*58b9f456SAndroid Build Coastguard Worker  template <size_t I, class T> struct variant_alternative<I, const T>;
94*58b9f456SAndroid Build Coastguard Worker  template <size_t I, class T> struct variant_alternative<I, volatile T>;
95*58b9f456SAndroid Build Coastguard Worker  template <size_t I, class T> struct variant_alternative<I, const volatile T>;
96*58b9f456SAndroid Build Coastguard Worker
97*58b9f456SAndroid Build Coastguard Worker  template <size_t I, class... Types>
98*58b9f456SAndroid Build Coastguard Worker  struct variant_alternative<I, variant<Types...>>;
99*58b9f456SAndroid Build Coastguard Worker
100*58b9f456SAndroid Build Coastguard Worker  inline constexpr size_t variant_npos = -1;
101*58b9f456SAndroid Build Coastguard Worker
102*58b9f456SAndroid Build Coastguard Worker  // 20.7.4, value access
103*58b9f456SAndroid Build Coastguard Worker  template <class T, class... Types>
104*58b9f456SAndroid Build Coastguard Worker  constexpr bool holds_alternative(const variant<Types...>&) noexcept;
105*58b9f456SAndroid Build Coastguard Worker
106*58b9f456SAndroid Build Coastguard Worker  template <size_t I, class... Types>
107*58b9f456SAndroid Build Coastguard Worker  constexpr variant_alternative_t<I, variant<Types...>>&
108*58b9f456SAndroid Build Coastguard Worker  get(variant<Types...>&);
109*58b9f456SAndroid Build Coastguard Worker
110*58b9f456SAndroid Build Coastguard Worker  template <size_t I, class... Types>
111*58b9f456SAndroid Build Coastguard Worker  constexpr variant_alternative_t<I, variant<Types...>>&&
112*58b9f456SAndroid Build Coastguard Worker  get(variant<Types...>&&);
113*58b9f456SAndroid Build Coastguard Worker
114*58b9f456SAndroid Build Coastguard Worker  template <size_t I, class... Types>
115*58b9f456SAndroid Build Coastguard Worker  constexpr variant_alternative_t<I, variant<Types...>> const&
116*58b9f456SAndroid Build Coastguard Worker  get(const variant<Types...>&);
117*58b9f456SAndroid Build Coastguard Worker
118*58b9f456SAndroid Build Coastguard Worker  template <size_t I, class... Types>
119*58b9f456SAndroid Build Coastguard Worker  constexpr variant_alternative_t<I, variant<Types...>> const&&
120*58b9f456SAndroid Build Coastguard Worker  get(const variant<Types...>&&);
121*58b9f456SAndroid Build Coastguard Worker
122*58b9f456SAndroid Build Coastguard Worker  template <class T, class...  Types>
123*58b9f456SAndroid Build Coastguard Worker  constexpr T& get(variant<Types...>&);
124*58b9f456SAndroid Build Coastguard Worker
125*58b9f456SAndroid Build Coastguard Worker  template <class T, class... Types>
126*58b9f456SAndroid Build Coastguard Worker  constexpr T&& get(variant<Types...>&&);
127*58b9f456SAndroid Build Coastguard Worker
128*58b9f456SAndroid Build Coastguard Worker  template <class T, class... Types>
129*58b9f456SAndroid Build Coastguard Worker  constexpr const T& get(const variant<Types...>&);
130*58b9f456SAndroid Build Coastguard Worker
131*58b9f456SAndroid Build Coastguard Worker  template <class T, class... Types>
132*58b9f456SAndroid Build Coastguard Worker  constexpr const T&& get(const variant<Types...>&&);
133*58b9f456SAndroid Build Coastguard Worker
134*58b9f456SAndroid Build Coastguard Worker  template <size_t I, class... Types>
135*58b9f456SAndroid Build Coastguard Worker  constexpr add_pointer_t<variant_alternative_t<I, variant<Types...>>>
136*58b9f456SAndroid Build Coastguard Worker  get_if(variant<Types...>*) noexcept;
137*58b9f456SAndroid Build Coastguard Worker
138*58b9f456SAndroid Build Coastguard Worker  template <size_t I, class... Types>
139*58b9f456SAndroid Build Coastguard Worker  constexpr add_pointer_t<const variant_alternative_t<I, variant<Types...>>>
140*58b9f456SAndroid Build Coastguard Worker  get_if(const variant<Types...>*) noexcept;
141*58b9f456SAndroid Build Coastguard Worker
142*58b9f456SAndroid Build Coastguard Worker  template <class T, class... Types>
143*58b9f456SAndroid Build Coastguard Worker  constexpr add_pointer_t<T>
144*58b9f456SAndroid Build Coastguard Worker  get_if(variant<Types...>*) noexcept;
145*58b9f456SAndroid Build Coastguard Worker
146*58b9f456SAndroid Build Coastguard Worker  template <class T, class... Types>
147*58b9f456SAndroid Build Coastguard Worker  constexpr add_pointer_t<const T>
148*58b9f456SAndroid Build Coastguard Worker  get_if(const variant<Types...>*) noexcept;
149*58b9f456SAndroid Build Coastguard Worker
150*58b9f456SAndroid Build Coastguard Worker  // 20.7.5, relational operators
151*58b9f456SAndroid Build Coastguard Worker  template <class... Types>
152*58b9f456SAndroid Build Coastguard Worker  constexpr bool operator==(const variant<Types...>&, const variant<Types...>&);
153*58b9f456SAndroid Build Coastguard Worker
154*58b9f456SAndroid Build Coastguard Worker  template <class... Types>
155*58b9f456SAndroid Build Coastguard Worker  constexpr bool operator!=(const variant<Types...>&, const variant<Types...>&);
156*58b9f456SAndroid Build Coastguard Worker
157*58b9f456SAndroid Build Coastguard Worker  template <class... Types>
158*58b9f456SAndroid Build Coastguard Worker  constexpr bool operator<(const variant<Types...>&, const variant<Types...>&);
159*58b9f456SAndroid Build Coastguard Worker
160*58b9f456SAndroid Build Coastguard Worker  template <class... Types>
161*58b9f456SAndroid Build Coastguard Worker  constexpr bool operator>(const variant<Types...>&, const variant<Types...>&);
162*58b9f456SAndroid Build Coastguard Worker
163*58b9f456SAndroid Build Coastguard Worker  template <class... Types>
164*58b9f456SAndroid Build Coastguard Worker  constexpr bool operator<=(const variant<Types...>&, const variant<Types...>&);
165*58b9f456SAndroid Build Coastguard Worker
166*58b9f456SAndroid Build Coastguard Worker  template <class... Types>
167*58b9f456SAndroid Build Coastguard Worker  constexpr bool operator>=(const variant<Types...>&, const variant<Types...>&);
168*58b9f456SAndroid Build Coastguard Worker
169*58b9f456SAndroid Build Coastguard Worker  // 20.7.6, visitation
170*58b9f456SAndroid Build Coastguard Worker  template <class Visitor, class... Variants>
171*58b9f456SAndroid Build Coastguard Worker  constexpr see below visit(Visitor&&, Variants&&...);
172*58b9f456SAndroid Build Coastguard Worker
173*58b9f456SAndroid Build Coastguard Worker  // 20.7.7, class monostate
174*58b9f456SAndroid Build Coastguard Worker  struct monostate;
175*58b9f456SAndroid Build Coastguard Worker
176*58b9f456SAndroid Build Coastguard Worker  // 20.7.8, monostate relational operators
177*58b9f456SAndroid Build Coastguard Worker  constexpr bool operator<(monostate, monostate) noexcept;
178*58b9f456SAndroid Build Coastguard Worker  constexpr bool operator>(monostate, monostate) noexcept;
179*58b9f456SAndroid Build Coastguard Worker  constexpr bool operator<=(monostate, monostate) noexcept;
180*58b9f456SAndroid Build Coastguard Worker  constexpr bool operator>=(monostate, monostate) noexcept;
181*58b9f456SAndroid Build Coastguard Worker  constexpr bool operator==(monostate, monostate) noexcept;
182*58b9f456SAndroid Build Coastguard Worker  constexpr bool operator!=(monostate, monostate) noexcept;
183*58b9f456SAndroid Build Coastguard Worker
184*58b9f456SAndroid Build Coastguard Worker  // 20.7.9, specialized algorithms
185*58b9f456SAndroid Build Coastguard Worker  template <class... Types>
186*58b9f456SAndroid Build Coastguard Worker  void swap(variant<Types...>&, variant<Types...>&) noexcept(see below);
187*58b9f456SAndroid Build Coastguard Worker
188*58b9f456SAndroid Build Coastguard Worker  // 20.7.10, class bad_variant_access
189*58b9f456SAndroid Build Coastguard Worker  class bad_variant_access;
190*58b9f456SAndroid Build Coastguard Worker
191*58b9f456SAndroid Build Coastguard Worker  // 20.7.11, hash support
192*58b9f456SAndroid Build Coastguard Worker  template <class T> struct hash;
193*58b9f456SAndroid Build Coastguard Worker  template <class... Types> struct hash<variant<Types...>>;
194*58b9f456SAndroid Build Coastguard Worker  template <> struct hash<monostate>;
195*58b9f456SAndroid Build Coastguard Worker
196*58b9f456SAndroid Build Coastguard Worker} // namespace std
197*58b9f456SAndroid Build Coastguard Worker
198*58b9f456SAndroid Build Coastguard Worker*/
199*58b9f456SAndroid Build Coastguard Worker
200*58b9f456SAndroid Build Coastguard Worker#include <__config>
201*58b9f456SAndroid Build Coastguard Worker#include <__tuple>
202*58b9f456SAndroid Build Coastguard Worker#include <array>
203*58b9f456SAndroid Build Coastguard Worker#include <exception>
204*58b9f456SAndroid Build Coastguard Worker#include <functional>
205*58b9f456SAndroid Build Coastguard Worker#include <initializer_list>
206*58b9f456SAndroid Build Coastguard Worker#include <new>
207*58b9f456SAndroid Build Coastguard Worker#include <tuple>
208*58b9f456SAndroid Build Coastguard Worker#include <type_traits>
209*58b9f456SAndroid Build Coastguard Worker#include <utility>
210*58b9f456SAndroid Build Coastguard Worker#include <limits>
211*58b9f456SAndroid Build Coastguard Worker#include <version>
212*58b9f456SAndroid Build Coastguard Worker
213*58b9f456SAndroid Build Coastguard Worker#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
214*58b9f456SAndroid Build Coastguard Worker#pragma GCC system_header
215*58b9f456SAndroid Build Coastguard Worker#endif
216*58b9f456SAndroid Build Coastguard Worker
217*58b9f456SAndroid Build Coastguard Worker_LIBCPP_PUSH_MACROS
218*58b9f456SAndroid Build Coastguard Worker#include <__undef_macros>
219*58b9f456SAndroid Build Coastguard Worker
220*58b9f456SAndroid Build Coastguard Workernamespace std { // explicitly not using versioning namespace
221*58b9f456SAndroid Build Coastguard Worker
222*58b9f456SAndroid Build Coastguard Workerclass _LIBCPP_EXCEPTION_ABI _LIBCPP_AVAILABILITY_BAD_VARIANT_ACCESS bad_variant_access : public exception {
223*58b9f456SAndroid Build Coastguard Workerpublic:
224*58b9f456SAndroid Build Coastguard Worker  virtual const char* what() const _NOEXCEPT;
225*58b9f456SAndroid Build Coastguard Worker};
226*58b9f456SAndroid Build Coastguard Worker
227*58b9f456SAndroid Build Coastguard Worker} // namespace std
228*58b9f456SAndroid Build Coastguard Worker
229*58b9f456SAndroid Build Coastguard Worker_LIBCPP_BEGIN_NAMESPACE_STD
230*58b9f456SAndroid Build Coastguard Worker
231*58b9f456SAndroid Build Coastguard Worker#if _LIBCPP_STD_VER > 14
232*58b9f456SAndroid Build Coastguard Worker
233*58b9f456SAndroid Build Coastguard Worker_LIBCPP_NORETURN
234*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
235*58b9f456SAndroid Build Coastguard Worker_LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS
236*58b9f456SAndroid Build Coastguard Workervoid __throw_bad_variant_access() {
237*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP_NO_EXCEPTIONS
238*58b9f456SAndroid Build Coastguard Worker        throw bad_variant_access();
239*58b9f456SAndroid Build Coastguard Worker#else
240*58b9f456SAndroid Build Coastguard Worker        _VSTD::abort();
241*58b9f456SAndroid Build Coastguard Worker#endif
242*58b9f456SAndroid Build Coastguard Worker}
243*58b9f456SAndroid Build Coastguard Worker
244*58b9f456SAndroid Build Coastguard Workertemplate <class... _Types>
245*58b9f456SAndroid Build Coastguard Workerclass _LIBCPP_TEMPLATE_VIS variant;
246*58b9f456SAndroid Build Coastguard Worker
247*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp>
248*58b9f456SAndroid Build Coastguard Workerstruct _LIBCPP_TEMPLATE_VIS variant_size;
249*58b9f456SAndroid Build Coastguard Worker
250*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp>
251*58b9f456SAndroid Build Coastguard Worker_LIBCPP_INLINE_VAR constexpr size_t variant_size_v = variant_size<_Tp>::value;
252*58b9f456SAndroid Build Coastguard Worker
253*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp>
254*58b9f456SAndroid Build Coastguard Workerstruct _LIBCPP_TEMPLATE_VIS variant_size<const _Tp> : variant_size<_Tp> {};
255*58b9f456SAndroid Build Coastguard Worker
256*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp>
257*58b9f456SAndroid Build Coastguard Workerstruct _LIBCPP_TEMPLATE_VIS variant_size<volatile _Tp> : variant_size<_Tp> {};
258*58b9f456SAndroid Build Coastguard Worker
259*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp>
260*58b9f456SAndroid Build Coastguard Workerstruct _LIBCPP_TEMPLATE_VIS variant_size<const volatile _Tp>
261*58b9f456SAndroid Build Coastguard Worker    : variant_size<_Tp> {};
262*58b9f456SAndroid Build Coastguard Worker
263*58b9f456SAndroid Build Coastguard Workertemplate <class... _Types>
264*58b9f456SAndroid Build Coastguard Workerstruct _LIBCPP_TEMPLATE_VIS variant_size<variant<_Types...>>
265*58b9f456SAndroid Build Coastguard Worker    : integral_constant<size_t, sizeof...(_Types)> {};
266*58b9f456SAndroid Build Coastguard Worker
267*58b9f456SAndroid Build Coastguard Workertemplate <size_t _Ip, class _Tp>
268*58b9f456SAndroid Build Coastguard Workerstruct _LIBCPP_TEMPLATE_VIS variant_alternative;
269*58b9f456SAndroid Build Coastguard Worker
270*58b9f456SAndroid Build Coastguard Workertemplate <size_t _Ip, class _Tp>
271*58b9f456SAndroid Build Coastguard Workerusing variant_alternative_t = typename variant_alternative<_Ip, _Tp>::type;
272*58b9f456SAndroid Build Coastguard Worker
273*58b9f456SAndroid Build Coastguard Workertemplate <size_t _Ip, class _Tp>
274*58b9f456SAndroid Build Coastguard Workerstruct _LIBCPP_TEMPLATE_VIS variant_alternative<_Ip, const _Tp>
275*58b9f456SAndroid Build Coastguard Worker    : add_const<variant_alternative_t<_Ip, _Tp>> {};
276*58b9f456SAndroid Build Coastguard Worker
277*58b9f456SAndroid Build Coastguard Workertemplate <size_t _Ip, class _Tp>
278*58b9f456SAndroid Build Coastguard Workerstruct _LIBCPP_TEMPLATE_VIS variant_alternative<_Ip, volatile _Tp>
279*58b9f456SAndroid Build Coastguard Worker    : add_volatile<variant_alternative_t<_Ip, _Tp>> {};
280*58b9f456SAndroid Build Coastguard Worker
281*58b9f456SAndroid Build Coastguard Workertemplate <size_t _Ip, class _Tp>
282*58b9f456SAndroid Build Coastguard Workerstruct _LIBCPP_TEMPLATE_VIS variant_alternative<_Ip, const volatile _Tp>
283*58b9f456SAndroid Build Coastguard Worker    : add_cv<variant_alternative_t<_Ip, _Tp>> {};
284*58b9f456SAndroid Build Coastguard Worker
285*58b9f456SAndroid Build Coastguard Workertemplate <size_t _Ip, class... _Types>
286*58b9f456SAndroid Build Coastguard Workerstruct _LIBCPP_TEMPLATE_VIS variant_alternative<_Ip, variant<_Types...>> {
287*58b9f456SAndroid Build Coastguard Worker  static_assert(_Ip < sizeof...(_Types), "Index out of bounds in std::variant_alternative<>");
288*58b9f456SAndroid Build Coastguard Worker  using type = __type_pack_element<_Ip, _Types...>;
289*58b9f456SAndroid Build Coastguard Worker};
290*58b9f456SAndroid Build Coastguard Worker
291*58b9f456SAndroid Build Coastguard Worker_LIBCPP_INLINE_VAR constexpr size_t variant_npos = static_cast<size_t>(-1);
292*58b9f456SAndroid Build Coastguard Worker
293*58b9f456SAndroid Build Coastguard Workerconstexpr int __choose_index_type(unsigned int __num_elem) {
294*58b9f456SAndroid Build Coastguard Worker  if (__num_elem < std::numeric_limits<unsigned char>::max())
295*58b9f456SAndroid Build Coastguard Worker    return 0;
296*58b9f456SAndroid Build Coastguard Worker  if (__num_elem < std::numeric_limits<unsigned short>::max())
297*58b9f456SAndroid Build Coastguard Worker    return 1;
298*58b9f456SAndroid Build Coastguard Worker  return 2;
299*58b9f456SAndroid Build Coastguard Worker}
300*58b9f456SAndroid Build Coastguard Worker
301*58b9f456SAndroid Build Coastguard Workertemplate <size_t _NumAlts>
302*58b9f456SAndroid Build Coastguard Workerusing __variant_index_t =
303*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP_ABI_VARIANT_INDEX_TYPE_OPTIMIZATION
304*58b9f456SAndroid Build Coastguard Worker  unsigned int;
305*58b9f456SAndroid Build Coastguard Worker#else
306*58b9f456SAndroid Build Coastguard Worker  std::tuple_element_t<
307*58b9f456SAndroid Build Coastguard Worker      __choose_index_type(_NumAlts),
308*58b9f456SAndroid Build Coastguard Worker      std::tuple<unsigned char, unsigned short, unsigned int>
309*58b9f456SAndroid Build Coastguard Worker  >;
310*58b9f456SAndroid Build Coastguard Worker#endif
311*58b9f456SAndroid Build Coastguard Worker
312*58b9f456SAndroid Build Coastguard Workertemplate <class _IndexType>
313*58b9f456SAndroid Build Coastguard Workerconstexpr _IndexType __variant_npos = static_cast<_IndexType>(-1);
314*58b9f456SAndroid Build Coastguard Worker
315*58b9f456SAndroid Build Coastguard Workernamespace __find_detail {
316*58b9f456SAndroid Build Coastguard Worker
317*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp, class... _Types>
318*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
319*58b9f456SAndroid Build Coastguard Workerconstexpr size_t __find_index() {
320*58b9f456SAndroid Build Coastguard Worker  constexpr bool __matches[] = {is_same_v<_Tp, _Types>...};
321*58b9f456SAndroid Build Coastguard Worker  size_t __result = __not_found;
322*58b9f456SAndroid Build Coastguard Worker  for (size_t __i = 0; __i < sizeof...(_Types); ++__i) {
323*58b9f456SAndroid Build Coastguard Worker    if (__matches[__i]) {
324*58b9f456SAndroid Build Coastguard Worker      if (__result != __not_found) {
325*58b9f456SAndroid Build Coastguard Worker        return __ambiguous;
326*58b9f456SAndroid Build Coastguard Worker      }
327*58b9f456SAndroid Build Coastguard Worker      __result = __i;
328*58b9f456SAndroid Build Coastguard Worker    }
329*58b9f456SAndroid Build Coastguard Worker  }
330*58b9f456SAndroid Build Coastguard Worker  return __result;
331*58b9f456SAndroid Build Coastguard Worker}
332*58b9f456SAndroid Build Coastguard Worker
333*58b9f456SAndroid Build Coastguard Workertemplate <size_t _Index>
334*58b9f456SAndroid Build Coastguard Workerstruct __find_unambiguous_index_sfinae_impl
335*58b9f456SAndroid Build Coastguard Worker    : integral_constant<size_t, _Index> {};
336*58b9f456SAndroid Build Coastguard Worker
337*58b9f456SAndroid Build Coastguard Workertemplate <>
338*58b9f456SAndroid Build Coastguard Workerstruct __find_unambiguous_index_sfinae_impl<__not_found> {};
339*58b9f456SAndroid Build Coastguard Worker
340*58b9f456SAndroid Build Coastguard Workertemplate <>
341*58b9f456SAndroid Build Coastguard Workerstruct __find_unambiguous_index_sfinae_impl<__ambiguous> {};
342*58b9f456SAndroid Build Coastguard Worker
343*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp, class... _Types>
344*58b9f456SAndroid Build Coastguard Workerstruct __find_unambiguous_index_sfinae
345*58b9f456SAndroid Build Coastguard Worker    : __find_unambiguous_index_sfinae_impl<__find_index<_Tp, _Types...>()> {};
346*58b9f456SAndroid Build Coastguard Worker
347*58b9f456SAndroid Build Coastguard Worker} // namespace __find_detail
348*58b9f456SAndroid Build Coastguard Worker
349*58b9f456SAndroid Build Coastguard Workernamespace __variant_detail {
350*58b9f456SAndroid Build Coastguard Worker
351*58b9f456SAndroid Build Coastguard Workerstruct __valueless_t {};
352*58b9f456SAndroid Build Coastguard Worker
353*58b9f456SAndroid Build Coastguard Workerenum class _Trait { _TriviallyAvailable, _Available, _Unavailable };
354*58b9f456SAndroid Build Coastguard Worker
355*58b9f456SAndroid Build Coastguard Workertemplate <typename _Tp,
356*58b9f456SAndroid Build Coastguard Worker          template <typename> class _IsTriviallyAvailable,
357*58b9f456SAndroid Build Coastguard Worker          template <typename> class _IsAvailable>
358*58b9f456SAndroid Build Coastguard Workerconstexpr _Trait __trait =
359*58b9f456SAndroid Build Coastguard Worker    _IsTriviallyAvailable<_Tp>::value
360*58b9f456SAndroid Build Coastguard Worker        ? _Trait::_TriviallyAvailable
361*58b9f456SAndroid Build Coastguard Worker        : _IsAvailable<_Tp>::value ? _Trait::_Available : _Trait::_Unavailable;
362*58b9f456SAndroid Build Coastguard Worker
363*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
364*58b9f456SAndroid Build Coastguard Workerconstexpr _Trait __common_trait(initializer_list<_Trait> __traits) {
365*58b9f456SAndroid Build Coastguard Worker  _Trait __result = _Trait::_TriviallyAvailable;
366*58b9f456SAndroid Build Coastguard Worker  for (_Trait __t : __traits) {
367*58b9f456SAndroid Build Coastguard Worker    if (static_cast<int>(__t) > static_cast<int>(__result)) {
368*58b9f456SAndroid Build Coastguard Worker      __result = __t;
369*58b9f456SAndroid Build Coastguard Worker    }
370*58b9f456SAndroid Build Coastguard Worker  }
371*58b9f456SAndroid Build Coastguard Worker  return __result;
372*58b9f456SAndroid Build Coastguard Worker}
373*58b9f456SAndroid Build Coastguard Worker
374*58b9f456SAndroid Build Coastguard Workertemplate <typename... _Types>
375*58b9f456SAndroid Build Coastguard Workerstruct __traits {
376*58b9f456SAndroid Build Coastguard Worker  static constexpr _Trait __copy_constructible_trait =
377*58b9f456SAndroid Build Coastguard Worker      __common_trait({__trait<_Types,
378*58b9f456SAndroid Build Coastguard Worker                              is_trivially_copy_constructible,
379*58b9f456SAndroid Build Coastguard Worker                              is_copy_constructible>...});
380*58b9f456SAndroid Build Coastguard Worker
381*58b9f456SAndroid Build Coastguard Worker  static constexpr _Trait __move_constructible_trait =
382*58b9f456SAndroid Build Coastguard Worker      __common_trait({__trait<_Types,
383*58b9f456SAndroid Build Coastguard Worker                              is_trivially_move_constructible,
384*58b9f456SAndroid Build Coastguard Worker                              is_move_constructible>...});
385*58b9f456SAndroid Build Coastguard Worker
386*58b9f456SAndroid Build Coastguard Worker  static constexpr _Trait __copy_assignable_trait = __common_trait(
387*58b9f456SAndroid Build Coastguard Worker      {__copy_constructible_trait,
388*58b9f456SAndroid Build Coastguard Worker       __trait<_Types, is_trivially_copy_assignable, is_copy_assignable>...});
389*58b9f456SAndroid Build Coastguard Worker
390*58b9f456SAndroid Build Coastguard Worker  static constexpr _Trait __move_assignable_trait = __common_trait(
391*58b9f456SAndroid Build Coastguard Worker      {__move_constructible_trait,
392*58b9f456SAndroid Build Coastguard Worker       __trait<_Types, is_trivially_move_assignable, is_move_assignable>...});
393*58b9f456SAndroid Build Coastguard Worker
394*58b9f456SAndroid Build Coastguard Worker  static constexpr _Trait __destructible_trait = __common_trait(
395*58b9f456SAndroid Build Coastguard Worker      {__trait<_Types, is_trivially_destructible, is_destructible>...});
396*58b9f456SAndroid Build Coastguard Worker};
397*58b9f456SAndroid Build Coastguard Worker
398*58b9f456SAndroid Build Coastguard Workernamespace __access {
399*58b9f456SAndroid Build Coastguard Worker
400*58b9f456SAndroid Build Coastguard Workerstruct __union {
401*58b9f456SAndroid Build Coastguard Worker  template <class _Vp>
402*58b9f456SAndroid Build Coastguard Worker  inline _LIBCPP_INLINE_VISIBILITY
403*58b9f456SAndroid Build Coastguard Worker  static constexpr auto&& __get_alt(_Vp&& __v, in_place_index_t<0>) {
404*58b9f456SAndroid Build Coastguard Worker    return _VSTD::forward<_Vp>(__v).__head;
405*58b9f456SAndroid Build Coastguard Worker  }
406*58b9f456SAndroid Build Coastguard Worker
407*58b9f456SAndroid Build Coastguard Worker  template <class _Vp, size_t _Ip>
408*58b9f456SAndroid Build Coastguard Worker  inline _LIBCPP_INLINE_VISIBILITY
409*58b9f456SAndroid Build Coastguard Worker  static constexpr auto&& __get_alt(_Vp&& __v, in_place_index_t<_Ip>) {
410*58b9f456SAndroid Build Coastguard Worker    return __get_alt(_VSTD::forward<_Vp>(__v).__tail, in_place_index<_Ip - 1>);
411*58b9f456SAndroid Build Coastguard Worker  }
412*58b9f456SAndroid Build Coastguard Worker};
413*58b9f456SAndroid Build Coastguard Worker
414*58b9f456SAndroid Build Coastguard Workerstruct __base {
415*58b9f456SAndroid Build Coastguard Worker  template <size_t _Ip, class _Vp>
416*58b9f456SAndroid Build Coastguard Worker  inline _LIBCPP_INLINE_VISIBILITY
417*58b9f456SAndroid Build Coastguard Worker  static constexpr auto&& __get_alt(_Vp&& __v) {
418*58b9f456SAndroid Build Coastguard Worker    return __union::__get_alt(_VSTD::forward<_Vp>(__v).__data,
419*58b9f456SAndroid Build Coastguard Worker                              in_place_index<_Ip>);
420*58b9f456SAndroid Build Coastguard Worker  }
421*58b9f456SAndroid Build Coastguard Worker};
422*58b9f456SAndroid Build Coastguard Worker
423*58b9f456SAndroid Build Coastguard Workerstruct __variant {
424*58b9f456SAndroid Build Coastguard Worker  template <size_t _Ip, class _Vp>
425*58b9f456SAndroid Build Coastguard Worker  inline _LIBCPP_INLINE_VISIBILITY
426*58b9f456SAndroid Build Coastguard Worker  static constexpr auto&& __get_alt(_Vp&& __v) {
427*58b9f456SAndroid Build Coastguard Worker    return __base::__get_alt<_Ip>(_VSTD::forward<_Vp>(__v).__impl);
428*58b9f456SAndroid Build Coastguard Worker  }
429*58b9f456SAndroid Build Coastguard Worker};
430*58b9f456SAndroid Build Coastguard Worker
431*58b9f456SAndroid Build Coastguard Worker} // namespace __access
432*58b9f456SAndroid Build Coastguard Worker
433*58b9f456SAndroid Build Coastguard Workernamespace __visitation {
434*58b9f456SAndroid Build Coastguard Worker
435*58b9f456SAndroid Build Coastguard Workerstruct __base {
436*58b9f456SAndroid Build Coastguard Worker  template <class _Visitor, class... _Vs>
437*58b9f456SAndroid Build Coastguard Worker  inline _LIBCPP_INLINE_VISIBILITY
438*58b9f456SAndroid Build Coastguard Worker  static constexpr decltype(auto)
439*58b9f456SAndroid Build Coastguard Worker  __visit_alt_at(size_t __index, _Visitor&& __visitor, _Vs&&... __vs) {
440*58b9f456SAndroid Build Coastguard Worker    constexpr auto __fdiagonal =
441*58b9f456SAndroid Build Coastguard Worker        __make_fdiagonal<_Visitor&&,
442*58b9f456SAndroid Build Coastguard Worker                         decltype(_VSTD::forward<_Vs>(__vs).__as_base())...>();
443*58b9f456SAndroid Build Coastguard Worker    return __fdiagonal[__index](_VSTD::forward<_Visitor>(__visitor),
444*58b9f456SAndroid Build Coastguard Worker                                _VSTD::forward<_Vs>(__vs).__as_base()...);
445*58b9f456SAndroid Build Coastguard Worker  }
446*58b9f456SAndroid Build Coastguard Worker
447*58b9f456SAndroid Build Coastguard Worker  template <class _Visitor, class... _Vs>
448*58b9f456SAndroid Build Coastguard Worker  inline _LIBCPP_INLINE_VISIBILITY
449*58b9f456SAndroid Build Coastguard Worker  static constexpr decltype(auto) __visit_alt(_Visitor&& __visitor,
450*58b9f456SAndroid Build Coastguard Worker                                              _Vs&&... __vs) {
451*58b9f456SAndroid Build Coastguard Worker    constexpr auto __fmatrix =
452*58b9f456SAndroid Build Coastguard Worker        __make_fmatrix<_Visitor&&,
453*58b9f456SAndroid Build Coastguard Worker                       decltype(_VSTD::forward<_Vs>(__vs).__as_base())...>();
454*58b9f456SAndroid Build Coastguard Worker    return __at(__fmatrix, __vs.index()...)(
455*58b9f456SAndroid Build Coastguard Worker        _VSTD::forward<_Visitor>(__visitor),
456*58b9f456SAndroid Build Coastguard Worker        _VSTD::forward<_Vs>(__vs).__as_base()...);
457*58b9f456SAndroid Build Coastguard Worker  }
458*58b9f456SAndroid Build Coastguard Worker
459*58b9f456SAndroid Build Coastguard Workerprivate:
460*58b9f456SAndroid Build Coastguard Worker  template <class _Tp>
461*58b9f456SAndroid Build Coastguard Worker  inline _LIBCPP_INLINE_VISIBILITY
462*58b9f456SAndroid Build Coastguard Worker  static constexpr const _Tp& __at(const _Tp& __elem) { return __elem; }
463*58b9f456SAndroid Build Coastguard Worker
464*58b9f456SAndroid Build Coastguard Worker  template <class _Tp, size_t _Np, typename... _Indices>
465*58b9f456SAndroid Build Coastguard Worker  inline _LIBCPP_INLINE_VISIBILITY
466*58b9f456SAndroid Build Coastguard Worker  static constexpr auto&& __at(const array<_Tp, _Np>& __elems,
467*58b9f456SAndroid Build Coastguard Worker                               size_t __index, _Indices... __indices) {
468*58b9f456SAndroid Build Coastguard Worker    return __at(__elems[__index], __indices...);
469*58b9f456SAndroid Build Coastguard Worker  }
470*58b9f456SAndroid Build Coastguard Worker
471*58b9f456SAndroid Build Coastguard Worker  template <class _Fp, class... _Fs>
472*58b9f456SAndroid Build Coastguard Worker  static constexpr void __std_visit_visitor_return_type_check() {
473*58b9f456SAndroid Build Coastguard Worker    static_assert(
474*58b9f456SAndroid Build Coastguard Worker        __all<is_same_v<_Fp, _Fs>...>::value,
475*58b9f456SAndroid Build Coastguard Worker        "`std::visit` requires the visitor to have a single return type.");
476*58b9f456SAndroid Build Coastguard Worker  }
477*58b9f456SAndroid Build Coastguard Worker
478*58b9f456SAndroid Build Coastguard Worker  template <class... _Fs>
479*58b9f456SAndroid Build Coastguard Worker  inline _LIBCPP_INLINE_VISIBILITY
480*58b9f456SAndroid Build Coastguard Worker  static constexpr auto __make_farray(_Fs&&... __fs) {
481*58b9f456SAndroid Build Coastguard Worker    __std_visit_visitor_return_type_check<__uncvref_t<_Fs>...>();
482*58b9f456SAndroid Build Coastguard Worker    using __result = array<common_type_t<__uncvref_t<_Fs>...>, sizeof...(_Fs)>;
483*58b9f456SAndroid Build Coastguard Worker    return __result{{_VSTD::forward<_Fs>(__fs)...}};
484*58b9f456SAndroid Build Coastguard Worker  }
485*58b9f456SAndroid Build Coastguard Worker
486*58b9f456SAndroid Build Coastguard Worker  template <std::size_t... _Is>
487*58b9f456SAndroid Build Coastguard Worker  struct __dispatcher {
488*58b9f456SAndroid Build Coastguard Worker    template <class _Fp, class... _Vs>
489*58b9f456SAndroid Build Coastguard Worker    inline _LIBCPP_INLINE_VISIBILITY
490*58b9f456SAndroid Build Coastguard Worker    static constexpr decltype(auto) __dispatch(_Fp __f, _Vs... __vs) {
491*58b9f456SAndroid Build Coastguard Worker        return __invoke_constexpr(
492*58b9f456SAndroid Build Coastguard Worker            static_cast<_Fp>(__f),
493*58b9f456SAndroid Build Coastguard Worker            __access::__base::__get_alt<_Is>(static_cast<_Vs>(__vs))...);
494*58b9f456SAndroid Build Coastguard Worker    }
495*58b9f456SAndroid Build Coastguard Worker  };
496*58b9f456SAndroid Build Coastguard Worker
497*58b9f456SAndroid Build Coastguard Worker  template <class _Fp, class... _Vs, size_t... _Is>
498*58b9f456SAndroid Build Coastguard Worker  inline _LIBCPP_INLINE_VISIBILITY
499*58b9f456SAndroid Build Coastguard Worker  static constexpr auto __make_dispatch(index_sequence<_Is...>) {
500*58b9f456SAndroid Build Coastguard Worker    return __dispatcher<_Is...>::template __dispatch<_Fp, _Vs...>;
501*58b9f456SAndroid Build Coastguard Worker  }
502*58b9f456SAndroid Build Coastguard Worker
503*58b9f456SAndroid Build Coastguard Worker  template <size_t _Ip, class _Fp, class... _Vs>
504*58b9f456SAndroid Build Coastguard Worker  inline _LIBCPP_INLINE_VISIBILITY
505*58b9f456SAndroid Build Coastguard Worker  static constexpr auto __make_fdiagonal_impl() {
506*58b9f456SAndroid Build Coastguard Worker    return __make_dispatch<_Fp, _Vs...>(
507*58b9f456SAndroid Build Coastguard Worker        index_sequence<(__identity<_Vs>{}, _Ip)...>{});
508*58b9f456SAndroid Build Coastguard Worker  }
509*58b9f456SAndroid Build Coastguard Worker
510*58b9f456SAndroid Build Coastguard Worker  template <class _Fp, class... _Vs, size_t... _Is>
511*58b9f456SAndroid Build Coastguard Worker  inline _LIBCPP_INLINE_VISIBILITY
512*58b9f456SAndroid Build Coastguard Worker  static constexpr auto __make_fdiagonal_impl(index_sequence<_Is...>) {
513*58b9f456SAndroid Build Coastguard Worker    return __base::__make_farray(__make_fdiagonal_impl<_Is, _Fp, _Vs...>()...);
514*58b9f456SAndroid Build Coastguard Worker  }
515*58b9f456SAndroid Build Coastguard Worker
516*58b9f456SAndroid Build Coastguard Worker  template <class _Fp, class _Vp, class... _Vs>
517*58b9f456SAndroid Build Coastguard Worker  inline _LIBCPP_INLINE_VISIBILITY
518*58b9f456SAndroid Build Coastguard Worker  static constexpr auto __make_fdiagonal() {
519*58b9f456SAndroid Build Coastguard Worker    constexpr size_t _Np = __uncvref_t<_Vp>::__size();
520*58b9f456SAndroid Build Coastguard Worker    static_assert(__all<(_Np == __uncvref_t<_Vs>::__size())...>::value);
521*58b9f456SAndroid Build Coastguard Worker    return __make_fdiagonal_impl<_Fp, _Vp, _Vs...>(make_index_sequence<_Np>{});
522*58b9f456SAndroid Build Coastguard Worker  }
523*58b9f456SAndroid Build Coastguard Worker
524*58b9f456SAndroid Build Coastguard Worker  template <class _Fp, class... _Vs, size_t... _Is>
525*58b9f456SAndroid Build Coastguard Worker  inline _LIBCPP_INLINE_VISIBILITY
526*58b9f456SAndroid Build Coastguard Worker  static constexpr auto __make_fmatrix_impl(index_sequence<_Is...> __is) {
527*58b9f456SAndroid Build Coastguard Worker    return __make_dispatch<_Fp, _Vs...>(__is);
528*58b9f456SAndroid Build Coastguard Worker  }
529*58b9f456SAndroid Build Coastguard Worker
530*58b9f456SAndroid Build Coastguard Worker  template <class _Fp, class... _Vs, size_t... _Is, size_t... _Js, class... _Ls>
531*58b9f456SAndroid Build Coastguard Worker  inline _LIBCPP_INLINE_VISIBILITY
532*58b9f456SAndroid Build Coastguard Worker  static constexpr auto __make_fmatrix_impl(index_sequence<_Is...>,
533*58b9f456SAndroid Build Coastguard Worker                                            index_sequence<_Js...>,
534*58b9f456SAndroid Build Coastguard Worker                                            _Ls... __ls) {
535*58b9f456SAndroid Build Coastguard Worker    return __base::__make_farray(__make_fmatrix_impl<_Fp, _Vs...>(
536*58b9f456SAndroid Build Coastguard Worker        index_sequence<_Is..., _Js>{}, __ls...)...);
537*58b9f456SAndroid Build Coastguard Worker  }
538*58b9f456SAndroid Build Coastguard Worker
539*58b9f456SAndroid Build Coastguard Worker  template <class _Fp, class... _Vs>
540*58b9f456SAndroid Build Coastguard Worker  inline _LIBCPP_INLINE_VISIBILITY
541*58b9f456SAndroid Build Coastguard Worker  static constexpr auto __make_fmatrix() {
542*58b9f456SAndroid Build Coastguard Worker    return __make_fmatrix_impl<_Fp, _Vs...>(
543*58b9f456SAndroid Build Coastguard Worker        index_sequence<>{}, make_index_sequence<__uncvref_t<_Vs>::__size()>{}...);
544*58b9f456SAndroid Build Coastguard Worker  }
545*58b9f456SAndroid Build Coastguard Worker};
546*58b9f456SAndroid Build Coastguard Worker
547*58b9f456SAndroid Build Coastguard Workerstruct __variant {
548*58b9f456SAndroid Build Coastguard Worker  template <class _Visitor, class... _Vs>
549*58b9f456SAndroid Build Coastguard Worker  inline _LIBCPP_INLINE_VISIBILITY
550*58b9f456SAndroid Build Coastguard Worker  static constexpr decltype(auto)
551*58b9f456SAndroid Build Coastguard Worker  __visit_alt_at(size_t __index, _Visitor&& __visitor, _Vs&&... __vs) {
552*58b9f456SAndroid Build Coastguard Worker    return __base::__visit_alt_at(__index,
553*58b9f456SAndroid Build Coastguard Worker                                  _VSTD::forward<_Visitor>(__visitor),
554*58b9f456SAndroid Build Coastguard Worker                                  _VSTD::forward<_Vs>(__vs).__impl...);
555*58b9f456SAndroid Build Coastguard Worker  }
556*58b9f456SAndroid Build Coastguard Worker
557*58b9f456SAndroid Build Coastguard Worker  template <class _Visitor, class... _Vs>
558*58b9f456SAndroid Build Coastguard Worker  inline _LIBCPP_INLINE_VISIBILITY
559*58b9f456SAndroid Build Coastguard Worker  static constexpr decltype(auto) __visit_alt(_Visitor&& __visitor,
560*58b9f456SAndroid Build Coastguard Worker                                              _Vs&&... __vs) {
561*58b9f456SAndroid Build Coastguard Worker    return __base::__visit_alt(_VSTD::forward<_Visitor>(__visitor),
562*58b9f456SAndroid Build Coastguard Worker                               _VSTD::forward<_Vs>(__vs).__impl...);
563*58b9f456SAndroid Build Coastguard Worker  }
564*58b9f456SAndroid Build Coastguard Worker
565*58b9f456SAndroid Build Coastguard Worker  template <class _Visitor, class... _Vs>
566*58b9f456SAndroid Build Coastguard Worker  inline _LIBCPP_INLINE_VISIBILITY
567*58b9f456SAndroid Build Coastguard Worker  static constexpr decltype(auto)
568*58b9f456SAndroid Build Coastguard Worker  __visit_value_at(size_t __index, _Visitor&& __visitor, _Vs&&... __vs) {
569*58b9f456SAndroid Build Coastguard Worker    return __visit_alt_at(
570*58b9f456SAndroid Build Coastguard Worker        __index,
571*58b9f456SAndroid Build Coastguard Worker        __make_value_visitor(_VSTD::forward<_Visitor>(__visitor)),
572*58b9f456SAndroid Build Coastguard Worker        _VSTD::forward<_Vs>(__vs)...);
573*58b9f456SAndroid Build Coastguard Worker  }
574*58b9f456SAndroid Build Coastguard Worker
575*58b9f456SAndroid Build Coastguard Worker  template <class _Visitor, class... _Vs>
576*58b9f456SAndroid Build Coastguard Worker  inline _LIBCPP_INLINE_VISIBILITY
577*58b9f456SAndroid Build Coastguard Worker  static constexpr decltype(auto) __visit_value(_Visitor&& __visitor,
578*58b9f456SAndroid Build Coastguard Worker                                                _Vs&&... __vs) {
579*58b9f456SAndroid Build Coastguard Worker    return __visit_alt(
580*58b9f456SAndroid Build Coastguard Worker        __make_value_visitor(_VSTD::forward<_Visitor>(__visitor)),
581*58b9f456SAndroid Build Coastguard Worker        _VSTD::forward<_Vs>(__vs)...);
582*58b9f456SAndroid Build Coastguard Worker  }
583*58b9f456SAndroid Build Coastguard Worker
584*58b9f456SAndroid Build Coastguard Workerprivate:
585*58b9f456SAndroid Build Coastguard Worker  template <class _Visitor, class... _Values>
586*58b9f456SAndroid Build Coastguard Worker  static constexpr void __std_visit_exhaustive_visitor_check() {
587*58b9f456SAndroid Build Coastguard Worker    static_assert(is_invocable_v<_Visitor, _Values...>,
588*58b9f456SAndroid Build Coastguard Worker                  "`std::visit` requires the visitor to be exhaustive.");
589*58b9f456SAndroid Build Coastguard Worker  }
590*58b9f456SAndroid Build Coastguard Worker
591*58b9f456SAndroid Build Coastguard Worker  template <class _Visitor>
592*58b9f456SAndroid Build Coastguard Worker  struct __value_visitor {
593*58b9f456SAndroid Build Coastguard Worker    template <class... _Alts>
594*58b9f456SAndroid Build Coastguard Worker    inline _LIBCPP_INLINE_VISIBILITY
595*58b9f456SAndroid Build Coastguard Worker    constexpr decltype(auto) operator()(_Alts&&... __alts) const {
596*58b9f456SAndroid Build Coastguard Worker      __std_visit_exhaustive_visitor_check<
597*58b9f456SAndroid Build Coastguard Worker          _Visitor,
598*58b9f456SAndroid Build Coastguard Worker          decltype((_VSTD::forward<_Alts>(__alts).__value))...>();
599*58b9f456SAndroid Build Coastguard Worker      return __invoke_constexpr(_VSTD::forward<_Visitor>(__visitor),
600*58b9f456SAndroid Build Coastguard Worker                                _VSTD::forward<_Alts>(__alts).__value...);
601*58b9f456SAndroid Build Coastguard Worker    }
602*58b9f456SAndroid Build Coastguard Worker    _Visitor&& __visitor;
603*58b9f456SAndroid Build Coastguard Worker  };
604*58b9f456SAndroid Build Coastguard Worker
605*58b9f456SAndroid Build Coastguard Worker  template <class _Visitor>
606*58b9f456SAndroid Build Coastguard Worker  inline _LIBCPP_INLINE_VISIBILITY
607*58b9f456SAndroid Build Coastguard Worker  static constexpr auto __make_value_visitor(_Visitor&& __visitor) {
608*58b9f456SAndroid Build Coastguard Worker    return __value_visitor<_Visitor>{_VSTD::forward<_Visitor>(__visitor)};
609*58b9f456SAndroid Build Coastguard Worker  }
610*58b9f456SAndroid Build Coastguard Worker};
611*58b9f456SAndroid Build Coastguard Worker
612*58b9f456SAndroid Build Coastguard Worker} // namespace __visitation
613*58b9f456SAndroid Build Coastguard Worker
614*58b9f456SAndroid Build Coastguard Workertemplate <size_t _Index, class _Tp>
615*58b9f456SAndroid Build Coastguard Workerstruct _LIBCPP_TEMPLATE_VIS __alt {
616*58b9f456SAndroid Build Coastguard Worker  using __value_type = _Tp;
617*58b9f456SAndroid Build Coastguard Worker
618*58b9f456SAndroid Build Coastguard Worker  template <class... _Args>
619*58b9f456SAndroid Build Coastguard Worker  inline _LIBCPP_INLINE_VISIBILITY
620*58b9f456SAndroid Build Coastguard Worker  explicit constexpr __alt(in_place_t, _Args&&... __args)
621*58b9f456SAndroid Build Coastguard Worker      : __value(_VSTD::forward<_Args>(__args)...) {}
622*58b9f456SAndroid Build Coastguard Worker
623*58b9f456SAndroid Build Coastguard Worker  __value_type __value;
624*58b9f456SAndroid Build Coastguard Worker};
625*58b9f456SAndroid Build Coastguard Worker
626*58b9f456SAndroid Build Coastguard Workertemplate <_Trait _DestructibleTrait, size_t _Index, class... _Types>
627*58b9f456SAndroid Build Coastguard Workerunion _LIBCPP_TEMPLATE_VIS __union;
628*58b9f456SAndroid Build Coastguard Worker
629*58b9f456SAndroid Build Coastguard Workertemplate <_Trait _DestructibleTrait, size_t _Index>
630*58b9f456SAndroid Build Coastguard Workerunion _LIBCPP_TEMPLATE_VIS __union<_DestructibleTrait, _Index> {};
631*58b9f456SAndroid Build Coastguard Worker
632*58b9f456SAndroid Build Coastguard Worker#define _LIBCPP_VARIANT_UNION(destructible_trait, destructor)                  \
633*58b9f456SAndroid Build Coastguard Worker  template <size_t _Index, class _Tp, class... _Types>                         \
634*58b9f456SAndroid Build Coastguard Worker  union _LIBCPP_TEMPLATE_VIS __union<destructible_trait,                      \
635*58b9f456SAndroid Build Coastguard Worker                                      _Index,                                  \
636*58b9f456SAndroid Build Coastguard Worker                                      _Tp,                                     \
637*58b9f456SAndroid Build Coastguard Worker                                      _Types...> {                             \
638*58b9f456SAndroid Build Coastguard Worker  public:                                                                      \
639*58b9f456SAndroid Build Coastguard Worker    inline _LIBCPP_INLINE_VISIBILITY                                           \
640*58b9f456SAndroid Build Coastguard Worker    explicit constexpr __union(__valueless_t) noexcept : __dummy{} {}          \
641*58b9f456SAndroid Build Coastguard Worker                                                                               \
642*58b9f456SAndroid Build Coastguard Worker    template <class... _Args>                                                  \
643*58b9f456SAndroid Build Coastguard Worker    inline _LIBCPP_INLINE_VISIBILITY                                           \
644*58b9f456SAndroid Build Coastguard Worker    explicit constexpr __union(in_place_index_t<0>, _Args&&... __args)         \
645*58b9f456SAndroid Build Coastguard Worker        : __head(in_place, _VSTD::forward<_Args>(__args)...) {}                \
646*58b9f456SAndroid Build Coastguard Worker                                                                               \
647*58b9f456SAndroid Build Coastguard Worker    template <size_t _Ip, class... _Args>                                      \
648*58b9f456SAndroid Build Coastguard Worker    inline _LIBCPP_INLINE_VISIBILITY                                           \
649*58b9f456SAndroid Build Coastguard Worker    explicit constexpr __union(in_place_index_t<_Ip>, _Args&&... __args)       \
650*58b9f456SAndroid Build Coastguard Worker        : __tail(in_place_index<_Ip - 1>, _VSTD::forward<_Args>(__args)...) {} \
651*58b9f456SAndroid Build Coastguard Worker                                                                               \
652*58b9f456SAndroid Build Coastguard Worker    __union(const __union&) = default;                                         \
653*58b9f456SAndroid Build Coastguard Worker    __union(__union&&) = default;                                              \
654*58b9f456SAndroid Build Coastguard Worker                                                                               \
655*58b9f456SAndroid Build Coastguard Worker    destructor                                                                 \
656*58b9f456SAndroid Build Coastguard Worker                                                                               \
657*58b9f456SAndroid Build Coastguard Worker    __union& operator=(const __union&) = default;                              \
658*58b9f456SAndroid Build Coastguard Worker    __union& operator=(__union&&) = default;                                   \
659*58b9f456SAndroid Build Coastguard Worker                                                                               \
660*58b9f456SAndroid Build Coastguard Worker  private:                                                                     \
661*58b9f456SAndroid Build Coastguard Worker    char __dummy;                                                              \
662*58b9f456SAndroid Build Coastguard Worker    __alt<_Index, _Tp> __head;                                                 \
663*58b9f456SAndroid Build Coastguard Worker    __union<destructible_trait, _Index + 1, _Types...> __tail;                 \
664*58b9f456SAndroid Build Coastguard Worker                                                                               \
665*58b9f456SAndroid Build Coastguard Worker    friend struct __access::__union;                                           \
666*58b9f456SAndroid Build Coastguard Worker  }
667*58b9f456SAndroid Build Coastguard Worker
668*58b9f456SAndroid Build Coastguard Worker_LIBCPP_VARIANT_UNION(_Trait::_TriviallyAvailable, ~__union() = default;);
669*58b9f456SAndroid Build Coastguard Worker_LIBCPP_VARIANT_UNION(_Trait::_Available, ~__union() {});
670*58b9f456SAndroid Build Coastguard Worker_LIBCPP_VARIANT_UNION(_Trait::_Unavailable, ~__union() = delete;);
671*58b9f456SAndroid Build Coastguard Worker
672*58b9f456SAndroid Build Coastguard Worker#undef _LIBCPP_VARIANT_UNION
673*58b9f456SAndroid Build Coastguard Worker
674*58b9f456SAndroid Build Coastguard Workertemplate <_Trait _DestructibleTrait, class... _Types>
675*58b9f456SAndroid Build Coastguard Workerclass _LIBCPP_TEMPLATE_VIS __base {
676*58b9f456SAndroid Build Coastguard Workerpublic:
677*58b9f456SAndroid Build Coastguard Worker  using __index_t = __variant_index_t<sizeof...(_Types)>;
678*58b9f456SAndroid Build Coastguard Worker
679*58b9f456SAndroid Build Coastguard Worker  inline _LIBCPP_INLINE_VISIBILITY
680*58b9f456SAndroid Build Coastguard Worker  explicit constexpr __base(__valueless_t tag) noexcept
681*58b9f456SAndroid Build Coastguard Worker      : __data(tag), __index(__variant_npos<__index_t>) {}
682*58b9f456SAndroid Build Coastguard Worker
683*58b9f456SAndroid Build Coastguard Worker  template <size_t _Ip, class... _Args>
684*58b9f456SAndroid Build Coastguard Worker  inline _LIBCPP_INLINE_VISIBILITY
685*58b9f456SAndroid Build Coastguard Worker  explicit constexpr __base(in_place_index_t<_Ip>, _Args&&... __args)
686*58b9f456SAndroid Build Coastguard Worker      :
687*58b9f456SAndroid Build Coastguard Worker        __data(in_place_index<_Ip>, _VSTD::forward<_Args>(__args)...),
688*58b9f456SAndroid Build Coastguard Worker        __index(_Ip) {}
689*58b9f456SAndroid Build Coastguard Worker
690*58b9f456SAndroid Build Coastguard Worker  inline _LIBCPP_INLINE_VISIBILITY
691*58b9f456SAndroid Build Coastguard Worker  constexpr bool valueless_by_exception() const noexcept {
692*58b9f456SAndroid Build Coastguard Worker    return index() == variant_npos;
693*58b9f456SAndroid Build Coastguard Worker  }
694*58b9f456SAndroid Build Coastguard Worker
695*58b9f456SAndroid Build Coastguard Worker  inline _LIBCPP_INLINE_VISIBILITY
696*58b9f456SAndroid Build Coastguard Worker  constexpr size_t index() const noexcept {
697*58b9f456SAndroid Build Coastguard Worker    return __index == __variant_npos<__index_t> ? variant_npos : __index;
698*58b9f456SAndroid Build Coastguard Worker  }
699*58b9f456SAndroid Build Coastguard Worker
700*58b9f456SAndroid Build Coastguard Workerprotected:
701*58b9f456SAndroid Build Coastguard Worker  inline _LIBCPP_INLINE_VISIBILITY
702*58b9f456SAndroid Build Coastguard Worker  constexpr auto&& __as_base() & { return *this; }
703*58b9f456SAndroid Build Coastguard Worker
704*58b9f456SAndroid Build Coastguard Worker  inline _LIBCPP_INLINE_VISIBILITY
705*58b9f456SAndroid Build Coastguard Worker  constexpr auto&& __as_base() && { return _VSTD::move(*this); }
706*58b9f456SAndroid Build Coastguard Worker
707*58b9f456SAndroid Build Coastguard Worker  inline _LIBCPP_INLINE_VISIBILITY
708*58b9f456SAndroid Build Coastguard Worker  constexpr auto&& __as_base() const & { return *this; }
709*58b9f456SAndroid Build Coastguard Worker
710*58b9f456SAndroid Build Coastguard Worker  inline _LIBCPP_INLINE_VISIBILITY
711*58b9f456SAndroid Build Coastguard Worker  constexpr auto&& __as_base() const && { return _VSTD::move(*this); }
712*58b9f456SAndroid Build Coastguard Worker
713*58b9f456SAndroid Build Coastguard Worker  inline _LIBCPP_INLINE_VISIBILITY
714*58b9f456SAndroid Build Coastguard Worker  static constexpr size_t __size() { return sizeof...(_Types); }
715*58b9f456SAndroid Build Coastguard Worker
716*58b9f456SAndroid Build Coastguard Worker  __union<_DestructibleTrait, 0, _Types...> __data;
717*58b9f456SAndroid Build Coastguard Worker  __index_t __index;
718*58b9f456SAndroid Build Coastguard Worker
719*58b9f456SAndroid Build Coastguard Worker  friend struct __access::__base;
720*58b9f456SAndroid Build Coastguard Worker  friend struct __visitation::__base;
721*58b9f456SAndroid Build Coastguard Worker};
722*58b9f456SAndroid Build Coastguard Worker
723*58b9f456SAndroid Build Coastguard Workertemplate <class _Traits, _Trait = _Traits::__destructible_trait>
724*58b9f456SAndroid Build Coastguard Workerclass _LIBCPP_TEMPLATE_VIS __destructor;
725*58b9f456SAndroid Build Coastguard Worker
726*58b9f456SAndroid Build Coastguard Worker#define _LIBCPP_VARIANT_DESTRUCTOR(destructible_trait, destructor, destroy)    \
727*58b9f456SAndroid Build Coastguard Worker  template <class... _Types>                                                   \
728*58b9f456SAndroid Build Coastguard Worker  class _LIBCPP_TEMPLATE_VIS __destructor<__traits<_Types...>,                 \
729*58b9f456SAndroid Build Coastguard Worker                                           destructible_trait>                 \
730*58b9f456SAndroid Build Coastguard Worker      : public __base<destructible_trait, _Types...> {                         \
731*58b9f456SAndroid Build Coastguard Worker    using __base_type = __base<destructible_trait, _Types...>;                 \
732*58b9f456SAndroid Build Coastguard Worker    using __index_t = typename __base_type::__index_t;                         \
733*58b9f456SAndroid Build Coastguard Worker                                                                               \
734*58b9f456SAndroid Build Coastguard Worker  public:                                                                      \
735*58b9f456SAndroid Build Coastguard Worker    using __base_type::__base_type;                                            \
736*58b9f456SAndroid Build Coastguard Worker    using __base_type::operator=;                                              \
737*58b9f456SAndroid Build Coastguard Worker                                                                               \
738*58b9f456SAndroid Build Coastguard Worker    __destructor(const __destructor&) = default;                               \
739*58b9f456SAndroid Build Coastguard Worker    __destructor(__destructor&&) = default;                                    \
740*58b9f456SAndroid Build Coastguard Worker    destructor                                                                 \
741*58b9f456SAndroid Build Coastguard Worker    __destructor& operator=(const __destructor&) = default;                    \
742*58b9f456SAndroid Build Coastguard Worker    __destructor& operator=(__destructor&&) = default;                         \
743*58b9f456SAndroid Build Coastguard Worker                                                                               \
744*58b9f456SAndroid Build Coastguard Worker  protected:                                                                   \
745*58b9f456SAndroid Build Coastguard Worker    inline _LIBCPP_INLINE_VISIBILITY                                           \
746*58b9f456SAndroid Build Coastguard Worker    destroy                                                                    \
747*58b9f456SAndroid Build Coastguard Worker  }
748*58b9f456SAndroid Build Coastguard Worker
749*58b9f456SAndroid Build Coastguard Worker_LIBCPP_VARIANT_DESTRUCTOR(
750*58b9f456SAndroid Build Coastguard Worker    _Trait::_TriviallyAvailable,
751*58b9f456SAndroid Build Coastguard Worker    ~__destructor() = default;,
752*58b9f456SAndroid Build Coastguard Worker    void __destroy() noexcept { this->__index = __variant_npos<__index_t>; });
753*58b9f456SAndroid Build Coastguard Worker
754*58b9f456SAndroid Build Coastguard Worker_LIBCPP_VARIANT_DESTRUCTOR(
755*58b9f456SAndroid Build Coastguard Worker    _Trait::_Available,
756*58b9f456SAndroid Build Coastguard Worker    ~__destructor() { __destroy(); },
757*58b9f456SAndroid Build Coastguard Worker    void __destroy() noexcept {
758*58b9f456SAndroid Build Coastguard Worker      if (!this->valueless_by_exception()) {
759*58b9f456SAndroid Build Coastguard Worker        __visitation::__base::__visit_alt(
760*58b9f456SAndroid Build Coastguard Worker            [](auto& __alt) noexcept {
761*58b9f456SAndroid Build Coastguard Worker              using __alt_type = __uncvref_t<decltype(__alt)>;
762*58b9f456SAndroid Build Coastguard Worker              __alt.~__alt_type();
763*58b9f456SAndroid Build Coastguard Worker            },
764*58b9f456SAndroid Build Coastguard Worker            *this);
765*58b9f456SAndroid Build Coastguard Worker      }
766*58b9f456SAndroid Build Coastguard Worker      this->__index = __variant_npos<__index_t>;
767*58b9f456SAndroid Build Coastguard Worker    });
768*58b9f456SAndroid Build Coastguard Worker
769*58b9f456SAndroid Build Coastguard Worker_LIBCPP_VARIANT_DESTRUCTOR(
770*58b9f456SAndroid Build Coastguard Worker    _Trait::_Unavailable,
771*58b9f456SAndroid Build Coastguard Worker    ~__destructor() = delete;,
772*58b9f456SAndroid Build Coastguard Worker    void __destroy() noexcept = delete;);
773*58b9f456SAndroid Build Coastguard Worker
774*58b9f456SAndroid Build Coastguard Worker#undef _LIBCPP_VARIANT_DESTRUCTOR
775*58b9f456SAndroid Build Coastguard Worker
776*58b9f456SAndroid Build Coastguard Workertemplate <class _Traits>
777*58b9f456SAndroid Build Coastguard Workerclass _LIBCPP_TEMPLATE_VIS __constructor : public __destructor<_Traits> {
778*58b9f456SAndroid Build Coastguard Worker  using __base_type = __destructor<_Traits>;
779*58b9f456SAndroid Build Coastguard Worker
780*58b9f456SAndroid Build Coastguard Workerpublic:
781*58b9f456SAndroid Build Coastguard Worker  using __base_type::__base_type;
782*58b9f456SAndroid Build Coastguard Worker  using __base_type::operator=;
783*58b9f456SAndroid Build Coastguard Worker
784*58b9f456SAndroid Build Coastguard Workerprotected:
785*58b9f456SAndroid Build Coastguard Worker  template <size_t _Ip, class _Tp, class... _Args>
786*58b9f456SAndroid Build Coastguard Worker  inline _LIBCPP_INLINE_VISIBILITY
787*58b9f456SAndroid Build Coastguard Worker  static _Tp& __construct_alt(__alt<_Ip, _Tp>& __a, _Args&&... __args) {
788*58b9f456SAndroid Build Coastguard Worker    ::new ((void*)_VSTD::addressof(__a))
789*58b9f456SAndroid Build Coastguard Worker        __alt<_Ip, _Tp>(in_place, _VSTD::forward<_Args>(__args)...);
790*58b9f456SAndroid Build Coastguard Worker    return __a.__value;
791*58b9f456SAndroid Build Coastguard Worker  }
792*58b9f456SAndroid Build Coastguard Worker
793*58b9f456SAndroid Build Coastguard Worker  template <class _Rhs>
794*58b9f456SAndroid Build Coastguard Worker  inline _LIBCPP_INLINE_VISIBILITY
795*58b9f456SAndroid Build Coastguard Worker  static void __generic_construct(__constructor& __lhs, _Rhs&& __rhs) {
796*58b9f456SAndroid Build Coastguard Worker    __lhs.__destroy();
797*58b9f456SAndroid Build Coastguard Worker    if (!__rhs.valueless_by_exception()) {
798*58b9f456SAndroid Build Coastguard Worker      __visitation::__base::__visit_alt_at(
799*58b9f456SAndroid Build Coastguard Worker          __rhs.index(),
800*58b9f456SAndroid Build Coastguard Worker          [](auto& __lhs_alt, auto&& __rhs_alt) {
801*58b9f456SAndroid Build Coastguard Worker            __construct_alt(
802*58b9f456SAndroid Build Coastguard Worker                __lhs_alt,
803*58b9f456SAndroid Build Coastguard Worker                _VSTD::forward<decltype(__rhs_alt)>(__rhs_alt).__value);
804*58b9f456SAndroid Build Coastguard Worker          },
805*58b9f456SAndroid Build Coastguard Worker          __lhs, _VSTD::forward<_Rhs>(__rhs));
806*58b9f456SAndroid Build Coastguard Worker      __lhs.__index = __rhs.index();
807*58b9f456SAndroid Build Coastguard Worker    }
808*58b9f456SAndroid Build Coastguard Worker  }
809*58b9f456SAndroid Build Coastguard Worker};
810*58b9f456SAndroid Build Coastguard Worker
811*58b9f456SAndroid Build Coastguard Workertemplate <class _Traits, _Trait = _Traits::__move_constructible_trait>
812*58b9f456SAndroid Build Coastguard Workerclass _LIBCPP_TEMPLATE_VIS __move_constructor;
813*58b9f456SAndroid Build Coastguard Worker
814*58b9f456SAndroid Build Coastguard Worker#define _LIBCPP_VARIANT_MOVE_CONSTRUCTOR(move_constructible_trait,             \
815*58b9f456SAndroid Build Coastguard Worker                                         move_constructor)                     \
816*58b9f456SAndroid Build Coastguard Worker  template <class... _Types>                                                   \
817*58b9f456SAndroid Build Coastguard Worker  class _LIBCPP_TEMPLATE_VIS __move_constructor<__traits<_Types...>,          \
818*58b9f456SAndroid Build Coastguard Worker                                                 move_constructible_trait>     \
819*58b9f456SAndroid Build Coastguard Worker      : public __constructor<__traits<_Types...>> {                            \
820*58b9f456SAndroid Build Coastguard Worker    using __base_type = __constructor<__traits<_Types...>>;                    \
821*58b9f456SAndroid Build Coastguard Worker                                                                               \
822*58b9f456SAndroid Build Coastguard Worker  public:                                                                      \
823*58b9f456SAndroid Build Coastguard Worker    using __base_type::__base_type;                                            \
824*58b9f456SAndroid Build Coastguard Worker    using __base_type::operator=;                                              \
825*58b9f456SAndroid Build Coastguard Worker                                                                               \
826*58b9f456SAndroid Build Coastguard Worker    __move_constructor(const __move_constructor&) = default;                   \
827*58b9f456SAndroid Build Coastguard Worker    move_constructor                                                           \
828*58b9f456SAndroid Build Coastguard Worker    ~__move_constructor() = default;                                           \
829*58b9f456SAndroid Build Coastguard Worker    __move_constructor& operator=(const __move_constructor&) = default;        \
830*58b9f456SAndroid Build Coastguard Worker    __move_constructor& operator=(__move_constructor&&) = default;             \
831*58b9f456SAndroid Build Coastguard Worker  }
832*58b9f456SAndroid Build Coastguard Worker
833*58b9f456SAndroid Build Coastguard Worker_LIBCPP_VARIANT_MOVE_CONSTRUCTOR(
834*58b9f456SAndroid Build Coastguard Worker    _Trait::_TriviallyAvailable,
835*58b9f456SAndroid Build Coastguard Worker    __move_constructor(__move_constructor&& __that) = default;);
836*58b9f456SAndroid Build Coastguard Worker
837*58b9f456SAndroid Build Coastguard Worker_LIBCPP_VARIANT_MOVE_CONSTRUCTOR(
838*58b9f456SAndroid Build Coastguard Worker    _Trait::_Available,
839*58b9f456SAndroid Build Coastguard Worker    __move_constructor(__move_constructor&& __that) noexcept(
840*58b9f456SAndroid Build Coastguard Worker        __all<is_nothrow_move_constructible_v<_Types>...>::value)
841*58b9f456SAndroid Build Coastguard Worker        : __move_constructor(__valueless_t{}) {
842*58b9f456SAndroid Build Coastguard Worker      this->__generic_construct(*this, _VSTD::move(__that));
843*58b9f456SAndroid Build Coastguard Worker    });
844*58b9f456SAndroid Build Coastguard Worker
845*58b9f456SAndroid Build Coastguard Worker_LIBCPP_VARIANT_MOVE_CONSTRUCTOR(
846*58b9f456SAndroid Build Coastguard Worker    _Trait::_Unavailable,
847*58b9f456SAndroid Build Coastguard Worker    __move_constructor(__move_constructor&&) = delete;);
848*58b9f456SAndroid Build Coastguard Worker
849*58b9f456SAndroid Build Coastguard Worker#undef _LIBCPP_VARIANT_MOVE_CONSTRUCTOR
850*58b9f456SAndroid Build Coastguard Worker
851*58b9f456SAndroid Build Coastguard Workertemplate <class _Traits, _Trait = _Traits::__copy_constructible_trait>
852*58b9f456SAndroid Build Coastguard Workerclass _LIBCPP_TEMPLATE_VIS __copy_constructor;
853*58b9f456SAndroid Build Coastguard Worker
854*58b9f456SAndroid Build Coastguard Worker#define _LIBCPP_VARIANT_COPY_CONSTRUCTOR(copy_constructible_trait,             \
855*58b9f456SAndroid Build Coastguard Worker                                         copy_constructor)                     \
856*58b9f456SAndroid Build Coastguard Worker  template <class... _Types>                                                   \
857*58b9f456SAndroid Build Coastguard Worker  class _LIBCPP_TEMPLATE_VIS __copy_constructor<__traits<_Types...>,          \
858*58b9f456SAndroid Build Coastguard Worker                                                 copy_constructible_trait>     \
859*58b9f456SAndroid Build Coastguard Worker      : public __move_constructor<__traits<_Types...>> {                       \
860*58b9f456SAndroid Build Coastguard Worker    using __base_type = __move_constructor<__traits<_Types...>>;               \
861*58b9f456SAndroid Build Coastguard Worker                                                                               \
862*58b9f456SAndroid Build Coastguard Worker  public:                                                                      \
863*58b9f456SAndroid Build Coastguard Worker    using __base_type::__base_type;                                            \
864*58b9f456SAndroid Build Coastguard Worker    using __base_type::operator=;                                              \
865*58b9f456SAndroid Build Coastguard Worker                                                                               \
866*58b9f456SAndroid Build Coastguard Worker    copy_constructor                                                           \
867*58b9f456SAndroid Build Coastguard Worker    __copy_constructor(__copy_constructor&&) = default;                        \
868*58b9f456SAndroid Build Coastguard Worker    ~__copy_constructor() = default;                                           \
869*58b9f456SAndroid Build Coastguard Worker    __copy_constructor& operator=(const __copy_constructor&) = default;        \
870*58b9f456SAndroid Build Coastguard Worker    __copy_constructor& operator=(__copy_constructor&&) = default;             \
871*58b9f456SAndroid Build Coastguard Worker  }
872*58b9f456SAndroid Build Coastguard Worker
873*58b9f456SAndroid Build Coastguard Worker_LIBCPP_VARIANT_COPY_CONSTRUCTOR(
874*58b9f456SAndroid Build Coastguard Worker    _Trait::_TriviallyAvailable,
875*58b9f456SAndroid Build Coastguard Worker    __copy_constructor(const __copy_constructor& __that) = default;);
876*58b9f456SAndroid Build Coastguard Worker
877*58b9f456SAndroid Build Coastguard Worker_LIBCPP_VARIANT_COPY_CONSTRUCTOR(
878*58b9f456SAndroid Build Coastguard Worker    _Trait::_Available,
879*58b9f456SAndroid Build Coastguard Worker    __copy_constructor(const __copy_constructor& __that)
880*58b9f456SAndroid Build Coastguard Worker        : __copy_constructor(__valueless_t{}) {
881*58b9f456SAndroid Build Coastguard Worker      this->__generic_construct(*this, __that);
882*58b9f456SAndroid Build Coastguard Worker    });
883*58b9f456SAndroid Build Coastguard Worker
884*58b9f456SAndroid Build Coastguard Worker_LIBCPP_VARIANT_COPY_CONSTRUCTOR(
885*58b9f456SAndroid Build Coastguard Worker    _Trait::_Unavailable,
886*58b9f456SAndroid Build Coastguard Worker    __copy_constructor(const __copy_constructor&) = delete;);
887*58b9f456SAndroid Build Coastguard Worker
888*58b9f456SAndroid Build Coastguard Worker#undef _LIBCPP_VARIANT_COPY_CONSTRUCTOR
889*58b9f456SAndroid Build Coastguard Worker
890*58b9f456SAndroid Build Coastguard Workertemplate <class _Traits>
891*58b9f456SAndroid Build Coastguard Workerclass _LIBCPP_TEMPLATE_VIS __assignment : public __copy_constructor<_Traits> {
892*58b9f456SAndroid Build Coastguard Worker  using __base_type = __copy_constructor<_Traits>;
893*58b9f456SAndroid Build Coastguard Worker
894*58b9f456SAndroid Build Coastguard Workerpublic:
895*58b9f456SAndroid Build Coastguard Worker  using __base_type::__base_type;
896*58b9f456SAndroid Build Coastguard Worker  using __base_type::operator=;
897*58b9f456SAndroid Build Coastguard Worker
898*58b9f456SAndroid Build Coastguard Worker  template <size_t _Ip, class... _Args>
899*58b9f456SAndroid Build Coastguard Worker  inline _LIBCPP_INLINE_VISIBILITY
900*58b9f456SAndroid Build Coastguard Worker  auto& __emplace(_Args&&... __args) {
901*58b9f456SAndroid Build Coastguard Worker    this->__destroy();
902*58b9f456SAndroid Build Coastguard Worker    auto& __res = this->__construct_alt(__access::__base::__get_alt<_Ip>(*this),
903*58b9f456SAndroid Build Coastguard Worker                          _VSTD::forward<_Args>(__args)...);
904*58b9f456SAndroid Build Coastguard Worker    this->__index = _Ip;
905*58b9f456SAndroid Build Coastguard Worker    return __res;
906*58b9f456SAndroid Build Coastguard Worker  }
907*58b9f456SAndroid Build Coastguard Worker
908*58b9f456SAndroid Build Coastguard Workerprotected:
909*58b9f456SAndroid Build Coastguard Worker  template <size_t _Ip, class _Tp, class _Arg>
910*58b9f456SAndroid Build Coastguard Worker  inline _LIBCPP_INLINE_VISIBILITY
911*58b9f456SAndroid Build Coastguard Worker  void __assign_alt(__alt<_Ip, _Tp>& __a, _Arg&& __arg) {
912*58b9f456SAndroid Build Coastguard Worker    if (this->index() == _Ip) {
913*58b9f456SAndroid Build Coastguard Worker      __a.__value = _VSTD::forward<_Arg>(__arg);
914*58b9f456SAndroid Build Coastguard Worker    } else {
915*58b9f456SAndroid Build Coastguard Worker      struct {
916*58b9f456SAndroid Build Coastguard Worker        void operator()(true_type) const {
917*58b9f456SAndroid Build Coastguard Worker          __this->__emplace<_Ip>(_VSTD::forward<_Arg>(__arg));
918*58b9f456SAndroid Build Coastguard Worker        }
919*58b9f456SAndroid Build Coastguard Worker        void operator()(false_type) const {
920*58b9f456SAndroid Build Coastguard Worker          __this->__emplace<_Ip>(_Tp(_VSTD::forward<_Arg>(__arg)));
921*58b9f456SAndroid Build Coastguard Worker        }
922*58b9f456SAndroid Build Coastguard Worker        __assignment* __this;
923*58b9f456SAndroid Build Coastguard Worker        _Arg&& __arg;
924*58b9f456SAndroid Build Coastguard Worker      } __impl{this, _VSTD::forward<_Arg>(__arg)};
925*58b9f456SAndroid Build Coastguard Worker      __impl(bool_constant<is_nothrow_constructible_v<_Tp, _Arg> ||
926*58b9f456SAndroid Build Coastguard Worker                           !is_nothrow_move_constructible_v<_Tp>>{});
927*58b9f456SAndroid Build Coastguard Worker    }
928*58b9f456SAndroid Build Coastguard Worker  }
929*58b9f456SAndroid Build Coastguard Worker
930*58b9f456SAndroid Build Coastguard Worker  template <class _That>
931*58b9f456SAndroid Build Coastguard Worker  inline _LIBCPP_INLINE_VISIBILITY
932*58b9f456SAndroid Build Coastguard Worker  void __generic_assign(_That&& __that) {
933*58b9f456SAndroid Build Coastguard Worker    if (this->valueless_by_exception() && __that.valueless_by_exception()) {
934*58b9f456SAndroid Build Coastguard Worker      // do nothing.
935*58b9f456SAndroid Build Coastguard Worker    } else if (__that.valueless_by_exception()) {
936*58b9f456SAndroid Build Coastguard Worker      this->__destroy();
937*58b9f456SAndroid Build Coastguard Worker    } else {
938*58b9f456SAndroid Build Coastguard Worker      __visitation::__base::__visit_alt_at(
939*58b9f456SAndroid Build Coastguard Worker          __that.index(),
940*58b9f456SAndroid Build Coastguard Worker          [this](auto& __this_alt, auto&& __that_alt) {
941*58b9f456SAndroid Build Coastguard Worker            this->__assign_alt(
942*58b9f456SAndroid Build Coastguard Worker                __this_alt,
943*58b9f456SAndroid Build Coastguard Worker                _VSTD::forward<decltype(__that_alt)>(__that_alt).__value);
944*58b9f456SAndroid Build Coastguard Worker          },
945*58b9f456SAndroid Build Coastguard Worker          *this, _VSTD::forward<_That>(__that));
946*58b9f456SAndroid Build Coastguard Worker    }
947*58b9f456SAndroid Build Coastguard Worker  }
948*58b9f456SAndroid Build Coastguard Worker};
949*58b9f456SAndroid Build Coastguard Worker
950*58b9f456SAndroid Build Coastguard Workertemplate <class _Traits, _Trait = _Traits::__move_assignable_trait>
951*58b9f456SAndroid Build Coastguard Workerclass _LIBCPP_TEMPLATE_VIS __move_assignment;
952*58b9f456SAndroid Build Coastguard Worker
953*58b9f456SAndroid Build Coastguard Worker#define _LIBCPP_VARIANT_MOVE_ASSIGNMENT(move_assignable_trait,                 \
954*58b9f456SAndroid Build Coastguard Worker                                        move_assignment)                       \
955*58b9f456SAndroid Build Coastguard Worker  template <class... _Types>                                                   \
956*58b9f456SAndroid Build Coastguard Worker  class _LIBCPP_TEMPLATE_VIS __move_assignment<__traits<_Types...>,           \
957*58b9f456SAndroid Build Coastguard Worker                                                move_assignable_trait>         \
958*58b9f456SAndroid Build Coastguard Worker      : public __assignment<__traits<_Types...>> {                             \
959*58b9f456SAndroid Build Coastguard Worker    using __base_type = __assignment<__traits<_Types...>>;                     \
960*58b9f456SAndroid Build Coastguard Worker                                                                               \
961*58b9f456SAndroid Build Coastguard Worker  public:                                                                      \
962*58b9f456SAndroid Build Coastguard Worker    using __base_type::__base_type;                                            \
963*58b9f456SAndroid Build Coastguard Worker    using __base_type::operator=;                                              \
964*58b9f456SAndroid Build Coastguard Worker                                                                               \
965*58b9f456SAndroid Build Coastguard Worker    __move_assignment(const __move_assignment&) = default;                     \
966*58b9f456SAndroid Build Coastguard Worker    __move_assignment(__move_assignment&&) = default;                          \
967*58b9f456SAndroid Build Coastguard Worker    ~__move_assignment() = default;                                            \
968*58b9f456SAndroid Build Coastguard Worker    __move_assignment& operator=(const __move_assignment&) = default;          \
969*58b9f456SAndroid Build Coastguard Worker    move_assignment                                                            \
970*58b9f456SAndroid Build Coastguard Worker  }
971*58b9f456SAndroid Build Coastguard Worker
972*58b9f456SAndroid Build Coastguard Worker_LIBCPP_VARIANT_MOVE_ASSIGNMENT(
973*58b9f456SAndroid Build Coastguard Worker    _Trait::_TriviallyAvailable,
974*58b9f456SAndroid Build Coastguard Worker    __move_assignment& operator=(__move_assignment&& __that) = default;);
975*58b9f456SAndroid Build Coastguard Worker
976*58b9f456SAndroid Build Coastguard Worker_LIBCPP_VARIANT_MOVE_ASSIGNMENT(
977*58b9f456SAndroid Build Coastguard Worker    _Trait::_Available,
978*58b9f456SAndroid Build Coastguard Worker    __move_assignment& operator=(__move_assignment&& __that) noexcept(
979*58b9f456SAndroid Build Coastguard Worker        __all<(is_nothrow_move_constructible_v<_Types> &&
980*58b9f456SAndroid Build Coastguard Worker               is_nothrow_move_assignable_v<_Types>)...>::value) {
981*58b9f456SAndroid Build Coastguard Worker      this->__generic_assign(_VSTD::move(__that));
982*58b9f456SAndroid Build Coastguard Worker      return *this;
983*58b9f456SAndroid Build Coastguard Worker    });
984*58b9f456SAndroid Build Coastguard Worker
985*58b9f456SAndroid Build Coastguard Worker_LIBCPP_VARIANT_MOVE_ASSIGNMENT(
986*58b9f456SAndroid Build Coastguard Worker    _Trait::_Unavailable,
987*58b9f456SAndroid Build Coastguard Worker    __move_assignment& operator=(__move_assignment&&) = delete;);
988*58b9f456SAndroid Build Coastguard Worker
989*58b9f456SAndroid Build Coastguard Worker#undef _LIBCPP_VARIANT_MOVE_ASSIGNMENT
990*58b9f456SAndroid Build Coastguard Worker
991*58b9f456SAndroid Build Coastguard Workertemplate <class _Traits, _Trait = _Traits::__copy_assignable_trait>
992*58b9f456SAndroid Build Coastguard Workerclass _LIBCPP_TEMPLATE_VIS __copy_assignment;
993*58b9f456SAndroid Build Coastguard Worker
994*58b9f456SAndroid Build Coastguard Worker#define _LIBCPP_VARIANT_COPY_ASSIGNMENT(copy_assignable_trait,                 \
995*58b9f456SAndroid Build Coastguard Worker                                        copy_assignment)                       \
996*58b9f456SAndroid Build Coastguard Worker  template <class... _Types>                                                   \
997*58b9f456SAndroid Build Coastguard Worker  class _LIBCPP_TEMPLATE_VIS __copy_assignment<__traits<_Types...>,           \
998*58b9f456SAndroid Build Coastguard Worker                                                copy_assignable_trait>         \
999*58b9f456SAndroid Build Coastguard Worker      : public __move_assignment<__traits<_Types...>> {                        \
1000*58b9f456SAndroid Build Coastguard Worker    using __base_type = __move_assignment<__traits<_Types...>>;                \
1001*58b9f456SAndroid Build Coastguard Worker                                                                               \
1002*58b9f456SAndroid Build Coastguard Worker  public:                                                                      \
1003*58b9f456SAndroid Build Coastguard Worker    using __base_type::__base_type;                                            \
1004*58b9f456SAndroid Build Coastguard Worker    using __base_type::operator=;                                              \
1005*58b9f456SAndroid Build Coastguard Worker                                                                               \
1006*58b9f456SAndroid Build Coastguard Worker    __copy_assignment(const __copy_assignment&) = default;                     \
1007*58b9f456SAndroid Build Coastguard Worker    __copy_assignment(__copy_assignment&&) = default;                          \
1008*58b9f456SAndroid Build Coastguard Worker    ~__copy_assignment() = default;                                            \
1009*58b9f456SAndroid Build Coastguard Worker    copy_assignment                                                            \
1010*58b9f456SAndroid Build Coastguard Worker    __copy_assignment& operator=(__copy_assignment&&) = default;               \
1011*58b9f456SAndroid Build Coastguard Worker  }
1012*58b9f456SAndroid Build Coastguard Worker
1013*58b9f456SAndroid Build Coastguard Worker_LIBCPP_VARIANT_COPY_ASSIGNMENT(
1014*58b9f456SAndroid Build Coastguard Worker    _Trait::_TriviallyAvailable,
1015*58b9f456SAndroid Build Coastguard Worker    __copy_assignment& operator=(const __copy_assignment& __that) = default;);
1016*58b9f456SAndroid Build Coastguard Worker
1017*58b9f456SAndroid Build Coastguard Worker_LIBCPP_VARIANT_COPY_ASSIGNMENT(
1018*58b9f456SAndroid Build Coastguard Worker    _Trait::_Available,
1019*58b9f456SAndroid Build Coastguard Worker    __copy_assignment& operator=(const __copy_assignment& __that) {
1020*58b9f456SAndroid Build Coastguard Worker      this->__generic_assign(__that);
1021*58b9f456SAndroid Build Coastguard Worker      return *this;
1022*58b9f456SAndroid Build Coastguard Worker    });
1023*58b9f456SAndroid Build Coastguard Worker
1024*58b9f456SAndroid Build Coastguard Worker_LIBCPP_VARIANT_COPY_ASSIGNMENT(
1025*58b9f456SAndroid Build Coastguard Worker    _Trait::_Unavailable,
1026*58b9f456SAndroid Build Coastguard Worker    __copy_assignment& operator=(const __copy_assignment&) = delete;);
1027*58b9f456SAndroid Build Coastguard Worker
1028*58b9f456SAndroid Build Coastguard Worker#undef _LIBCPP_VARIANT_COPY_ASSIGNMENT
1029*58b9f456SAndroid Build Coastguard Worker
1030*58b9f456SAndroid Build Coastguard Workertemplate <class... _Types>
1031*58b9f456SAndroid Build Coastguard Workerclass _LIBCPP_TEMPLATE_VIS __impl
1032*58b9f456SAndroid Build Coastguard Worker    : public __copy_assignment<__traits<_Types...>> {
1033*58b9f456SAndroid Build Coastguard Worker  using __base_type = __copy_assignment<__traits<_Types...>>;
1034*58b9f456SAndroid Build Coastguard Worker
1035*58b9f456SAndroid Build Coastguard Workerpublic:
1036*58b9f456SAndroid Build Coastguard Worker  using __base_type::__base_type;
1037*58b9f456SAndroid Build Coastguard Worker  using __base_type::operator=;
1038*58b9f456SAndroid Build Coastguard Worker
1039*58b9f456SAndroid Build Coastguard Worker  template <size_t _Ip, class _Arg>
1040*58b9f456SAndroid Build Coastguard Worker  inline _LIBCPP_INLINE_VISIBILITY
1041*58b9f456SAndroid Build Coastguard Worker  void __assign(_Arg&& __arg) {
1042*58b9f456SAndroid Build Coastguard Worker    this->__assign_alt(__access::__base::__get_alt<_Ip>(*this),
1043*58b9f456SAndroid Build Coastguard Worker                       _VSTD::forward<_Arg>(__arg));
1044*58b9f456SAndroid Build Coastguard Worker  }
1045*58b9f456SAndroid Build Coastguard Worker
1046*58b9f456SAndroid Build Coastguard Worker  inline _LIBCPP_INLINE_VISIBILITY
1047*58b9f456SAndroid Build Coastguard Worker  void __swap(__impl& __that)  {
1048*58b9f456SAndroid Build Coastguard Worker    if (this->valueless_by_exception() && __that.valueless_by_exception()) {
1049*58b9f456SAndroid Build Coastguard Worker      // do nothing.
1050*58b9f456SAndroid Build Coastguard Worker    } else if (this->index() == __that.index()) {
1051*58b9f456SAndroid Build Coastguard Worker      __visitation::__base::__visit_alt_at(
1052*58b9f456SAndroid Build Coastguard Worker          this->index(),
1053*58b9f456SAndroid Build Coastguard Worker          [](auto& __this_alt, auto& __that_alt) {
1054*58b9f456SAndroid Build Coastguard Worker            using _VSTD::swap;
1055*58b9f456SAndroid Build Coastguard Worker            swap(__this_alt.__value, __that_alt.__value);
1056*58b9f456SAndroid Build Coastguard Worker          },
1057*58b9f456SAndroid Build Coastguard Worker          *this,
1058*58b9f456SAndroid Build Coastguard Worker          __that);
1059*58b9f456SAndroid Build Coastguard Worker    } else {
1060*58b9f456SAndroid Build Coastguard Worker      __impl* __lhs = this;
1061*58b9f456SAndroid Build Coastguard Worker      __impl* __rhs = _VSTD::addressof(__that);
1062*58b9f456SAndroid Build Coastguard Worker      if (__lhs->__move_nothrow() && !__rhs->__move_nothrow()) {
1063*58b9f456SAndroid Build Coastguard Worker        _VSTD::swap(__lhs, __rhs);
1064*58b9f456SAndroid Build Coastguard Worker      }
1065*58b9f456SAndroid Build Coastguard Worker      __impl __tmp(_VSTD::move(*__rhs));
1066*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP_NO_EXCEPTIONS
1067*58b9f456SAndroid Build Coastguard Worker      // EXTENSION: When the move construction of `__lhs` into `__rhs` throws
1068*58b9f456SAndroid Build Coastguard Worker      // and `__tmp` is nothrow move constructible then we move `__tmp` back
1069*58b9f456SAndroid Build Coastguard Worker      // into `__rhs` and provide the strong exception safety guarantee.
1070*58b9f456SAndroid Build Coastguard Worker      try {
1071*58b9f456SAndroid Build Coastguard Worker        this->__generic_construct(*__rhs, _VSTD::move(*__lhs));
1072*58b9f456SAndroid Build Coastguard Worker      } catch (...) {
1073*58b9f456SAndroid Build Coastguard Worker        if (__tmp.__move_nothrow()) {
1074*58b9f456SAndroid Build Coastguard Worker          this->__generic_construct(*__rhs, _VSTD::move(__tmp));
1075*58b9f456SAndroid Build Coastguard Worker        }
1076*58b9f456SAndroid Build Coastguard Worker        throw;
1077*58b9f456SAndroid Build Coastguard Worker      }
1078*58b9f456SAndroid Build Coastguard Worker#else
1079*58b9f456SAndroid Build Coastguard Worker      this->__generic_construct(*__rhs, _VSTD::move(*__lhs));
1080*58b9f456SAndroid Build Coastguard Worker#endif
1081*58b9f456SAndroid Build Coastguard Worker      this->__generic_construct(*__lhs, _VSTD::move(__tmp));
1082*58b9f456SAndroid Build Coastguard Worker    }
1083*58b9f456SAndroid Build Coastguard Worker  }
1084*58b9f456SAndroid Build Coastguard Worker
1085*58b9f456SAndroid Build Coastguard Workerprivate:
1086*58b9f456SAndroid Build Coastguard Worker  inline _LIBCPP_INLINE_VISIBILITY
1087*58b9f456SAndroid Build Coastguard Worker  bool __move_nothrow() const {
1088*58b9f456SAndroid Build Coastguard Worker    constexpr bool __results[] = {is_nothrow_move_constructible_v<_Types>...};
1089*58b9f456SAndroid Build Coastguard Worker    return this->valueless_by_exception() || __results[this->index()];
1090*58b9f456SAndroid Build Coastguard Worker  }
1091*58b9f456SAndroid Build Coastguard Worker};
1092*58b9f456SAndroid Build Coastguard Worker
1093*58b9f456SAndroid Build Coastguard Workertemplate <class... _Types>
1094*58b9f456SAndroid Build Coastguard Workerstruct __overload;
1095*58b9f456SAndroid Build Coastguard Worker
1096*58b9f456SAndroid Build Coastguard Workertemplate <>
1097*58b9f456SAndroid Build Coastguard Workerstruct __overload<> { void operator()() const; };
1098*58b9f456SAndroid Build Coastguard Worker
1099*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp, class... _Types>
1100*58b9f456SAndroid Build Coastguard Workerstruct __overload<_Tp, _Types...> : __overload<_Types...> {
1101*58b9f456SAndroid Build Coastguard Worker  using __overload<_Types...>::operator();
1102*58b9f456SAndroid Build Coastguard Worker  __identity<_Tp> operator()(_Tp) const;
1103*58b9f456SAndroid Build Coastguard Worker};
1104*58b9f456SAndroid Build Coastguard Worker
1105*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp, class... _Types>
1106*58b9f456SAndroid Build Coastguard Workerusing __best_match_t = typename result_of_t<__overload<_Types...>(_Tp&&)>::type;
1107*58b9f456SAndroid Build Coastguard Worker
1108*58b9f456SAndroid Build Coastguard Worker} // __variant_detail
1109*58b9f456SAndroid Build Coastguard Worker
1110*58b9f456SAndroid Build Coastguard Workertemplate <class... _Types>
1111*58b9f456SAndroid Build Coastguard Workerclass _LIBCPP_TEMPLATE_VIS variant
1112*58b9f456SAndroid Build Coastguard Worker    : private __sfinae_ctor_base<
1113*58b9f456SAndroid Build Coastguard Worker          __all<is_copy_constructible_v<_Types>...>::value,
1114*58b9f456SAndroid Build Coastguard Worker          __all<is_move_constructible_v<_Types>...>::value>,
1115*58b9f456SAndroid Build Coastguard Worker      private __sfinae_assign_base<
1116*58b9f456SAndroid Build Coastguard Worker          __all<(is_copy_constructible_v<_Types> &&
1117*58b9f456SAndroid Build Coastguard Worker                 is_copy_assignable_v<_Types>)...>::value,
1118*58b9f456SAndroid Build Coastguard Worker          __all<(is_move_constructible_v<_Types> &&
1119*58b9f456SAndroid Build Coastguard Worker                 is_move_assignable_v<_Types>)...>::value> {
1120*58b9f456SAndroid Build Coastguard Worker  static_assert(0 < sizeof...(_Types),
1121*58b9f456SAndroid Build Coastguard Worker                "variant must consist of at least one alternative.");
1122*58b9f456SAndroid Build Coastguard Worker
1123*58b9f456SAndroid Build Coastguard Worker  static_assert(__all<!is_array_v<_Types>...>::value,
1124*58b9f456SAndroid Build Coastguard Worker                "variant can not have an array type as an alternative.");
1125*58b9f456SAndroid Build Coastguard Worker
1126*58b9f456SAndroid Build Coastguard Worker  static_assert(__all<!is_reference_v<_Types>...>::value,
1127*58b9f456SAndroid Build Coastguard Worker                "variant can not have a reference type as an alternative.");
1128*58b9f456SAndroid Build Coastguard Worker
1129*58b9f456SAndroid Build Coastguard Worker  static_assert(__all<!is_void_v<_Types>...>::value,
1130*58b9f456SAndroid Build Coastguard Worker                "variant can not have a void type as an alternative.");
1131*58b9f456SAndroid Build Coastguard Worker
1132*58b9f456SAndroid Build Coastguard Worker  using __first_type = variant_alternative_t<0, variant>;
1133*58b9f456SAndroid Build Coastguard Worker
1134*58b9f456SAndroid Build Coastguard Workerpublic:
1135*58b9f456SAndroid Build Coastguard Worker  template <bool _Dummy = true,
1136*58b9f456SAndroid Build Coastguard Worker            enable_if_t<__dependent_type<is_default_constructible<__first_type>,
1137*58b9f456SAndroid Build Coastguard Worker                                         _Dummy>::value,
1138*58b9f456SAndroid Build Coastguard Worker                        int> = 0>
1139*58b9f456SAndroid Build Coastguard Worker  inline _LIBCPP_INLINE_VISIBILITY
1140*58b9f456SAndroid Build Coastguard Worker  constexpr variant() noexcept(is_nothrow_default_constructible_v<__first_type>)
1141*58b9f456SAndroid Build Coastguard Worker      : __impl(in_place_index<0>) {}
1142*58b9f456SAndroid Build Coastguard Worker
1143*58b9f456SAndroid Build Coastguard Worker  variant(const variant&) = default;
1144*58b9f456SAndroid Build Coastguard Worker  variant(variant&&) = default;
1145*58b9f456SAndroid Build Coastguard Worker
1146*58b9f456SAndroid Build Coastguard Worker  template <
1147*58b9f456SAndroid Build Coastguard Worker      class _Arg,
1148*58b9f456SAndroid Build Coastguard Worker      enable_if_t<!is_same_v<__uncvref_t<_Arg>, variant>, int> = 0,
1149*58b9f456SAndroid Build Coastguard Worker      enable_if_t<!__is_inplace_type<__uncvref_t<_Arg>>::value, int> = 0,
1150*58b9f456SAndroid Build Coastguard Worker      enable_if_t<!__is_inplace_index<__uncvref_t<_Arg>>::value, int> = 0,
1151*58b9f456SAndroid Build Coastguard Worker      class _Tp = __variant_detail::__best_match_t<_Arg, _Types...>,
1152*58b9f456SAndroid Build Coastguard Worker      size_t _Ip =
1153*58b9f456SAndroid Build Coastguard Worker          __find_detail::__find_unambiguous_index_sfinae<_Tp, _Types...>::value,
1154*58b9f456SAndroid Build Coastguard Worker      enable_if_t<is_constructible_v<_Tp, _Arg>, int> = 0>
1155*58b9f456SAndroid Build Coastguard Worker  inline _LIBCPP_INLINE_VISIBILITY
1156*58b9f456SAndroid Build Coastguard Worker  constexpr variant(_Arg&& __arg) noexcept(
1157*58b9f456SAndroid Build Coastguard Worker      is_nothrow_constructible_v<_Tp, _Arg>)
1158*58b9f456SAndroid Build Coastguard Worker      : __impl(in_place_index<_Ip>, _VSTD::forward<_Arg>(__arg)) {}
1159*58b9f456SAndroid Build Coastguard Worker
1160*58b9f456SAndroid Build Coastguard Worker  template <size_t _Ip, class... _Args,
1161*58b9f456SAndroid Build Coastguard Worker            class = enable_if_t<(_Ip < sizeof...(_Types)), int>,
1162*58b9f456SAndroid Build Coastguard Worker            class _Tp = variant_alternative_t<_Ip, variant<_Types...>>,
1163*58b9f456SAndroid Build Coastguard Worker            enable_if_t<is_constructible_v<_Tp, _Args...>, int> = 0>
1164*58b9f456SAndroid Build Coastguard Worker  inline _LIBCPP_INLINE_VISIBILITY
1165*58b9f456SAndroid Build Coastguard Worker  explicit constexpr variant(
1166*58b9f456SAndroid Build Coastguard Worker      in_place_index_t<_Ip>,
1167*58b9f456SAndroid Build Coastguard Worker      _Args&&... __args) noexcept(is_nothrow_constructible_v<_Tp, _Args...>)
1168*58b9f456SAndroid Build Coastguard Worker      : __impl(in_place_index<_Ip>, _VSTD::forward<_Args>(__args)...) {}
1169*58b9f456SAndroid Build Coastguard Worker
1170*58b9f456SAndroid Build Coastguard Worker  template <
1171*58b9f456SAndroid Build Coastguard Worker      size_t _Ip,
1172*58b9f456SAndroid Build Coastguard Worker      class _Up,
1173*58b9f456SAndroid Build Coastguard Worker      class... _Args,
1174*58b9f456SAndroid Build Coastguard Worker      enable_if_t<(_Ip < sizeof...(_Types)), int> = 0,
1175*58b9f456SAndroid Build Coastguard Worker      class _Tp = variant_alternative_t<_Ip, variant<_Types...>>,
1176*58b9f456SAndroid Build Coastguard Worker      enable_if_t<is_constructible_v<_Tp, initializer_list<_Up>&, _Args...>,
1177*58b9f456SAndroid Build Coastguard Worker                  int> = 0>
1178*58b9f456SAndroid Build Coastguard Worker  inline _LIBCPP_INLINE_VISIBILITY
1179*58b9f456SAndroid Build Coastguard Worker  explicit constexpr variant(
1180*58b9f456SAndroid Build Coastguard Worker      in_place_index_t<_Ip>,
1181*58b9f456SAndroid Build Coastguard Worker      initializer_list<_Up> __il,
1182*58b9f456SAndroid Build Coastguard Worker      _Args&&... __args) noexcept(
1183*58b9f456SAndroid Build Coastguard Worker      is_nothrow_constructible_v<_Tp, initializer_list<_Up>&, _Args...>)
1184*58b9f456SAndroid Build Coastguard Worker      : __impl(in_place_index<_Ip>, __il, _VSTD::forward<_Args>(__args)...) {}
1185*58b9f456SAndroid Build Coastguard Worker
1186*58b9f456SAndroid Build Coastguard Worker  template <
1187*58b9f456SAndroid Build Coastguard Worker      class _Tp,
1188*58b9f456SAndroid Build Coastguard Worker      class... _Args,
1189*58b9f456SAndroid Build Coastguard Worker      size_t _Ip =
1190*58b9f456SAndroid Build Coastguard Worker          __find_detail::__find_unambiguous_index_sfinae<_Tp, _Types...>::value,
1191*58b9f456SAndroid Build Coastguard Worker      enable_if_t<is_constructible_v<_Tp, _Args...>, int> = 0>
1192*58b9f456SAndroid Build Coastguard Worker  inline _LIBCPP_INLINE_VISIBILITY
1193*58b9f456SAndroid Build Coastguard Worker  explicit constexpr variant(in_place_type_t<_Tp>, _Args&&... __args) noexcept(
1194*58b9f456SAndroid Build Coastguard Worker      is_nothrow_constructible_v<_Tp, _Args...>)
1195*58b9f456SAndroid Build Coastguard Worker      : __impl(in_place_index<_Ip>, _VSTD::forward<_Args>(__args)...) {}
1196*58b9f456SAndroid Build Coastguard Worker
1197*58b9f456SAndroid Build Coastguard Worker  template <
1198*58b9f456SAndroid Build Coastguard Worker      class _Tp,
1199*58b9f456SAndroid Build Coastguard Worker      class _Up,
1200*58b9f456SAndroid Build Coastguard Worker      class... _Args,
1201*58b9f456SAndroid Build Coastguard Worker      size_t _Ip =
1202*58b9f456SAndroid Build Coastguard Worker          __find_detail::__find_unambiguous_index_sfinae<_Tp, _Types...>::value,
1203*58b9f456SAndroid Build Coastguard Worker      enable_if_t<is_constructible_v<_Tp, initializer_list<_Up>&, _Args...>,
1204*58b9f456SAndroid Build Coastguard Worker                  int> = 0>
1205*58b9f456SAndroid Build Coastguard Worker  inline _LIBCPP_INLINE_VISIBILITY
1206*58b9f456SAndroid Build Coastguard Worker  explicit constexpr variant(
1207*58b9f456SAndroid Build Coastguard Worker      in_place_type_t<_Tp>,
1208*58b9f456SAndroid Build Coastguard Worker      initializer_list<_Up> __il,
1209*58b9f456SAndroid Build Coastguard Worker      _Args&&... __args) noexcept(
1210*58b9f456SAndroid Build Coastguard Worker      is_nothrow_constructible_v<_Tp, initializer_list< _Up>&, _Args...>)
1211*58b9f456SAndroid Build Coastguard Worker      : __impl(in_place_index<_Ip>, __il, _VSTD::forward<_Args>(__args)...) {}
1212*58b9f456SAndroid Build Coastguard Worker
1213*58b9f456SAndroid Build Coastguard Worker  ~variant() = default;
1214*58b9f456SAndroid Build Coastguard Worker
1215*58b9f456SAndroid Build Coastguard Worker  variant& operator=(const variant&) = default;
1216*58b9f456SAndroid Build Coastguard Worker  variant& operator=(variant&&) = default;
1217*58b9f456SAndroid Build Coastguard Worker
1218*58b9f456SAndroid Build Coastguard Worker  template <
1219*58b9f456SAndroid Build Coastguard Worker      class _Arg,
1220*58b9f456SAndroid Build Coastguard Worker      enable_if_t<!is_same_v<__uncvref_t<_Arg>, variant>, int> = 0,
1221*58b9f456SAndroid Build Coastguard Worker      class _Tp = __variant_detail::__best_match_t<_Arg, _Types...>,
1222*58b9f456SAndroid Build Coastguard Worker      size_t _Ip =
1223*58b9f456SAndroid Build Coastguard Worker          __find_detail::__find_unambiguous_index_sfinae<_Tp, _Types...>::value,
1224*58b9f456SAndroid Build Coastguard Worker      enable_if_t<is_assignable_v<_Tp&, _Arg> && is_constructible_v<_Tp, _Arg>,
1225*58b9f456SAndroid Build Coastguard Worker                  int> = 0>
1226*58b9f456SAndroid Build Coastguard Worker  inline _LIBCPP_INLINE_VISIBILITY
1227*58b9f456SAndroid Build Coastguard Worker  variant& operator=(_Arg&& __arg) noexcept(
1228*58b9f456SAndroid Build Coastguard Worker      is_nothrow_assignable_v<_Tp&, _Arg> &&
1229*58b9f456SAndroid Build Coastguard Worker      is_nothrow_constructible_v<_Tp, _Arg>) {
1230*58b9f456SAndroid Build Coastguard Worker    __impl.template __assign<_Ip>(_VSTD::forward<_Arg>(__arg));
1231*58b9f456SAndroid Build Coastguard Worker    return *this;
1232*58b9f456SAndroid Build Coastguard Worker  }
1233*58b9f456SAndroid Build Coastguard Worker
1234*58b9f456SAndroid Build Coastguard Worker  template <
1235*58b9f456SAndroid Build Coastguard Worker      size_t _Ip,
1236*58b9f456SAndroid Build Coastguard Worker      class... _Args,
1237*58b9f456SAndroid Build Coastguard Worker      enable_if_t<(_Ip < sizeof...(_Types)), int> = 0,
1238*58b9f456SAndroid Build Coastguard Worker      class _Tp = variant_alternative_t<_Ip, variant<_Types...>>,
1239*58b9f456SAndroid Build Coastguard Worker      enable_if_t<is_constructible_v<_Tp, _Args...>, int> = 0>
1240*58b9f456SAndroid Build Coastguard Worker  inline _LIBCPP_INLINE_VISIBILITY
1241*58b9f456SAndroid Build Coastguard Worker  _Tp& emplace(_Args&&... __args) {
1242*58b9f456SAndroid Build Coastguard Worker    return __impl.template __emplace<_Ip>(_VSTD::forward<_Args>(__args)...);
1243*58b9f456SAndroid Build Coastguard Worker  }
1244*58b9f456SAndroid Build Coastguard Worker
1245*58b9f456SAndroid Build Coastguard Worker  template <
1246*58b9f456SAndroid Build Coastguard Worker      size_t _Ip,
1247*58b9f456SAndroid Build Coastguard Worker      class _Up,
1248*58b9f456SAndroid Build Coastguard Worker      class... _Args,
1249*58b9f456SAndroid Build Coastguard Worker      enable_if_t<(_Ip < sizeof...(_Types)), int> = 0,
1250*58b9f456SAndroid Build Coastguard Worker      class _Tp = variant_alternative_t<_Ip, variant<_Types...>>,
1251*58b9f456SAndroid Build Coastguard Worker      enable_if_t<is_constructible_v<_Tp, initializer_list<_Up>&, _Args...>,
1252*58b9f456SAndroid Build Coastguard Worker                  int> = 0>
1253*58b9f456SAndroid Build Coastguard Worker  inline _LIBCPP_INLINE_VISIBILITY
1254*58b9f456SAndroid Build Coastguard Worker  _Tp& emplace(initializer_list<_Up> __il, _Args&&... __args) {
1255*58b9f456SAndroid Build Coastguard Worker    return __impl.template __emplace<_Ip>(__il, _VSTD::forward<_Args>(__args)...);
1256*58b9f456SAndroid Build Coastguard Worker  }
1257*58b9f456SAndroid Build Coastguard Worker
1258*58b9f456SAndroid Build Coastguard Worker  template <
1259*58b9f456SAndroid Build Coastguard Worker      class _Tp,
1260*58b9f456SAndroid Build Coastguard Worker      class... _Args,
1261*58b9f456SAndroid Build Coastguard Worker      size_t _Ip =
1262*58b9f456SAndroid Build Coastguard Worker          __find_detail::__find_unambiguous_index_sfinae<_Tp, _Types...>::value,
1263*58b9f456SAndroid Build Coastguard Worker      enable_if_t<is_constructible_v<_Tp, _Args...>, int> = 0>
1264*58b9f456SAndroid Build Coastguard Worker  inline _LIBCPP_INLINE_VISIBILITY
1265*58b9f456SAndroid Build Coastguard Worker  _Tp& emplace(_Args&&... __args) {
1266*58b9f456SAndroid Build Coastguard Worker    return __impl.template __emplace<_Ip>(_VSTD::forward<_Args>(__args)...);
1267*58b9f456SAndroid Build Coastguard Worker  }
1268*58b9f456SAndroid Build Coastguard Worker
1269*58b9f456SAndroid Build Coastguard Worker  template <
1270*58b9f456SAndroid Build Coastguard Worker      class _Tp,
1271*58b9f456SAndroid Build Coastguard Worker      class _Up,
1272*58b9f456SAndroid Build Coastguard Worker      class... _Args,
1273*58b9f456SAndroid Build Coastguard Worker      size_t _Ip =
1274*58b9f456SAndroid Build Coastguard Worker          __find_detail::__find_unambiguous_index_sfinae<_Tp, _Types...>::value,
1275*58b9f456SAndroid Build Coastguard Worker      enable_if_t<is_constructible_v<_Tp, initializer_list<_Up>&, _Args...>,
1276*58b9f456SAndroid Build Coastguard Worker                  int> = 0>
1277*58b9f456SAndroid Build Coastguard Worker  inline _LIBCPP_INLINE_VISIBILITY
1278*58b9f456SAndroid Build Coastguard Worker  _Tp& emplace(initializer_list<_Up> __il, _Args&&... __args) {
1279*58b9f456SAndroid Build Coastguard Worker    return __impl.template __emplace<_Ip>(__il, _VSTD::forward<_Args>(__args)...);
1280*58b9f456SAndroid Build Coastguard Worker  }
1281*58b9f456SAndroid Build Coastguard Worker
1282*58b9f456SAndroid Build Coastguard Worker  inline _LIBCPP_INLINE_VISIBILITY
1283*58b9f456SAndroid Build Coastguard Worker  constexpr bool valueless_by_exception() const noexcept {
1284*58b9f456SAndroid Build Coastguard Worker    return __impl.valueless_by_exception();
1285*58b9f456SAndroid Build Coastguard Worker  }
1286*58b9f456SAndroid Build Coastguard Worker
1287*58b9f456SAndroid Build Coastguard Worker  inline _LIBCPP_INLINE_VISIBILITY
1288*58b9f456SAndroid Build Coastguard Worker  constexpr size_t index() const noexcept { return __impl.index(); }
1289*58b9f456SAndroid Build Coastguard Worker
1290*58b9f456SAndroid Build Coastguard Worker  template <
1291*58b9f456SAndroid Build Coastguard Worker      bool _Dummy = true,
1292*58b9f456SAndroid Build Coastguard Worker      enable_if_t<
1293*58b9f456SAndroid Build Coastguard Worker          __all<(
1294*58b9f456SAndroid Build Coastguard Worker              __dependent_type<is_move_constructible<_Types>, _Dummy>::value &&
1295*58b9f456SAndroid Build Coastguard Worker              __dependent_type<is_swappable<_Types>, _Dummy>::value)...>::value,
1296*58b9f456SAndroid Build Coastguard Worker          int> = 0>
1297*58b9f456SAndroid Build Coastguard Worker  inline _LIBCPP_INLINE_VISIBILITY
1298*58b9f456SAndroid Build Coastguard Worker  void swap(variant& __that) noexcept(
1299*58b9f456SAndroid Build Coastguard Worker      __all<(is_nothrow_move_constructible_v<_Types> &&
1300*58b9f456SAndroid Build Coastguard Worker             is_nothrow_swappable_v<_Types>)...>::value) {
1301*58b9f456SAndroid Build Coastguard Worker    __impl.__swap(__that.__impl);
1302*58b9f456SAndroid Build Coastguard Worker  }
1303*58b9f456SAndroid Build Coastguard Worker
1304*58b9f456SAndroid Build Coastguard Workerprivate:
1305*58b9f456SAndroid Build Coastguard Worker  __variant_detail::__impl<_Types...> __impl;
1306*58b9f456SAndroid Build Coastguard Worker
1307*58b9f456SAndroid Build Coastguard Worker  friend struct __variant_detail::__access::__variant;
1308*58b9f456SAndroid Build Coastguard Worker  friend struct __variant_detail::__visitation::__variant;
1309*58b9f456SAndroid Build Coastguard Worker};
1310*58b9f456SAndroid Build Coastguard Worker
1311*58b9f456SAndroid Build Coastguard Workertemplate <size_t _Ip, class... _Types>
1312*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
1313*58b9f456SAndroid Build Coastguard Workerconstexpr bool __holds_alternative(const variant<_Types...>& __v) noexcept {
1314*58b9f456SAndroid Build Coastguard Worker  return __v.index() == _Ip;
1315*58b9f456SAndroid Build Coastguard Worker}
1316*58b9f456SAndroid Build Coastguard Worker
1317*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp, class... _Types>
1318*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
1319*58b9f456SAndroid Build Coastguard Workerconstexpr bool holds_alternative(const variant<_Types...>& __v) noexcept {
1320*58b9f456SAndroid Build Coastguard Worker  return __holds_alternative<__find_exactly_one_t<_Tp, _Types...>::value>(__v);
1321*58b9f456SAndroid Build Coastguard Worker}
1322*58b9f456SAndroid Build Coastguard Worker
1323*58b9f456SAndroid Build Coastguard Workertemplate <size_t _Ip, class _Vp>
1324*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
1325*58b9f456SAndroid Build Coastguard Worker_LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS
1326*58b9f456SAndroid Build Coastguard Workerconstexpr auto&& __generic_get(_Vp&& __v) {
1327*58b9f456SAndroid Build Coastguard Worker  using __variant_detail::__access::__variant;
1328*58b9f456SAndroid Build Coastguard Worker  if (!__holds_alternative<_Ip>(__v)) {
1329*58b9f456SAndroid Build Coastguard Worker    __throw_bad_variant_access();
1330*58b9f456SAndroid Build Coastguard Worker  }
1331*58b9f456SAndroid Build Coastguard Worker  return __variant::__get_alt<_Ip>(_VSTD::forward<_Vp>(__v)).__value;
1332*58b9f456SAndroid Build Coastguard Worker}
1333*58b9f456SAndroid Build Coastguard Worker
1334*58b9f456SAndroid Build Coastguard Workertemplate <size_t _Ip, class... _Types>
1335*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
1336*58b9f456SAndroid Build Coastguard Worker_LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS
1337*58b9f456SAndroid Build Coastguard Workerconstexpr variant_alternative_t<_Ip, variant<_Types...>>& get(
1338*58b9f456SAndroid Build Coastguard Worker    variant<_Types...>& __v) {
1339*58b9f456SAndroid Build Coastguard Worker  static_assert(_Ip < sizeof...(_Types));
1340*58b9f456SAndroid Build Coastguard Worker  static_assert(!is_void_v<variant_alternative_t<_Ip, variant<_Types...>>>);
1341*58b9f456SAndroid Build Coastguard Worker  return __generic_get<_Ip>(__v);
1342*58b9f456SAndroid Build Coastguard Worker}
1343*58b9f456SAndroid Build Coastguard Worker
1344*58b9f456SAndroid Build Coastguard Workertemplate <size_t _Ip, class... _Types>
1345*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
1346*58b9f456SAndroid Build Coastguard Worker_LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS
1347*58b9f456SAndroid Build Coastguard Workerconstexpr variant_alternative_t<_Ip, variant<_Types...>>&& get(
1348*58b9f456SAndroid Build Coastguard Worker    variant<_Types...>&& __v) {
1349*58b9f456SAndroid Build Coastguard Worker  static_assert(_Ip < sizeof...(_Types));
1350*58b9f456SAndroid Build Coastguard Worker  static_assert(!is_void_v<variant_alternative_t<_Ip, variant<_Types...>>>);
1351*58b9f456SAndroid Build Coastguard Worker  return __generic_get<_Ip>(_VSTD::move(__v));
1352*58b9f456SAndroid Build Coastguard Worker}
1353*58b9f456SAndroid Build Coastguard Worker
1354*58b9f456SAndroid Build Coastguard Workertemplate <size_t _Ip, class... _Types>
1355*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
1356*58b9f456SAndroid Build Coastguard Worker_LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS
1357*58b9f456SAndroid Build Coastguard Workerconstexpr const variant_alternative_t<_Ip, variant<_Types...>>& get(
1358*58b9f456SAndroid Build Coastguard Worker    const variant<_Types...>& __v) {
1359*58b9f456SAndroid Build Coastguard Worker  static_assert(_Ip < sizeof...(_Types));
1360*58b9f456SAndroid Build Coastguard Worker  static_assert(!is_void_v<variant_alternative_t<_Ip, variant<_Types...>>>);
1361*58b9f456SAndroid Build Coastguard Worker  return __generic_get<_Ip>(__v);
1362*58b9f456SAndroid Build Coastguard Worker}
1363*58b9f456SAndroid Build Coastguard Worker
1364*58b9f456SAndroid Build Coastguard Workertemplate <size_t _Ip, class... _Types>
1365*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
1366*58b9f456SAndroid Build Coastguard Worker_LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS
1367*58b9f456SAndroid Build Coastguard Workerconstexpr const variant_alternative_t<_Ip, variant<_Types...>>&& get(
1368*58b9f456SAndroid Build Coastguard Worker    const variant<_Types...>&& __v) {
1369*58b9f456SAndroid Build Coastguard Worker  static_assert(_Ip < sizeof...(_Types));
1370*58b9f456SAndroid Build Coastguard Worker  static_assert(!is_void_v<variant_alternative_t<_Ip, variant<_Types...>>>);
1371*58b9f456SAndroid Build Coastguard Worker  return __generic_get<_Ip>(_VSTD::move(__v));
1372*58b9f456SAndroid Build Coastguard Worker}
1373*58b9f456SAndroid Build Coastguard Worker
1374*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp, class... _Types>
1375*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
1376*58b9f456SAndroid Build Coastguard Worker_LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS
1377*58b9f456SAndroid Build Coastguard Workerconstexpr _Tp& get(variant<_Types...>& __v) {
1378*58b9f456SAndroid Build Coastguard Worker  static_assert(!is_void_v<_Tp>);
1379*58b9f456SAndroid Build Coastguard Worker  return _VSTD::get<__find_exactly_one_t<_Tp, _Types...>::value>(__v);
1380*58b9f456SAndroid Build Coastguard Worker}
1381*58b9f456SAndroid Build Coastguard Worker
1382*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp, class... _Types>
1383*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
1384*58b9f456SAndroid Build Coastguard Worker_LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS
1385*58b9f456SAndroid Build Coastguard Workerconstexpr _Tp&& get(variant<_Types...>&& __v) {
1386*58b9f456SAndroid Build Coastguard Worker  static_assert(!is_void_v<_Tp>);
1387*58b9f456SAndroid Build Coastguard Worker  return _VSTD::get<__find_exactly_one_t<_Tp, _Types...>::value>(
1388*58b9f456SAndroid Build Coastguard Worker      _VSTD::move(__v));
1389*58b9f456SAndroid Build Coastguard Worker}
1390*58b9f456SAndroid Build Coastguard Worker
1391*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp, class... _Types>
1392*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
1393*58b9f456SAndroid Build Coastguard Worker_LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS
1394*58b9f456SAndroid Build Coastguard Workerconstexpr const _Tp& get(const variant<_Types...>& __v) {
1395*58b9f456SAndroid Build Coastguard Worker  static_assert(!is_void_v<_Tp>);
1396*58b9f456SAndroid Build Coastguard Worker  return _VSTD::get<__find_exactly_one_t<_Tp, _Types...>::value>(__v);
1397*58b9f456SAndroid Build Coastguard Worker}
1398*58b9f456SAndroid Build Coastguard Worker
1399*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp, class... _Types>
1400*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
1401*58b9f456SAndroid Build Coastguard Worker_LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS
1402*58b9f456SAndroid Build Coastguard Workerconstexpr const _Tp&& get(const variant<_Types...>&& __v) {
1403*58b9f456SAndroid Build Coastguard Worker  static_assert(!is_void_v<_Tp>);
1404*58b9f456SAndroid Build Coastguard Worker  return _VSTD::get<__find_exactly_one_t<_Tp, _Types...>::value>(
1405*58b9f456SAndroid Build Coastguard Worker      _VSTD::move(__v));
1406*58b9f456SAndroid Build Coastguard Worker}
1407*58b9f456SAndroid Build Coastguard Worker
1408*58b9f456SAndroid Build Coastguard Workertemplate <size_t _Ip, class _Vp>
1409*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
1410*58b9f456SAndroid Build Coastguard Workerconstexpr auto* __generic_get_if(_Vp* __v) noexcept {
1411*58b9f456SAndroid Build Coastguard Worker  using __variant_detail::__access::__variant;
1412*58b9f456SAndroid Build Coastguard Worker  return __v && __holds_alternative<_Ip>(*__v)
1413*58b9f456SAndroid Build Coastguard Worker             ? _VSTD::addressof(__variant::__get_alt<_Ip>(*__v).__value)
1414*58b9f456SAndroid Build Coastguard Worker             : nullptr;
1415*58b9f456SAndroid Build Coastguard Worker}
1416*58b9f456SAndroid Build Coastguard Worker
1417*58b9f456SAndroid Build Coastguard Workertemplate <size_t _Ip, class... _Types>
1418*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
1419*58b9f456SAndroid Build Coastguard Workerconstexpr add_pointer_t<variant_alternative_t<_Ip, variant<_Types...>>>
1420*58b9f456SAndroid Build Coastguard Workerget_if(variant<_Types...>* __v) noexcept {
1421*58b9f456SAndroid Build Coastguard Worker  static_assert(_Ip < sizeof...(_Types));
1422*58b9f456SAndroid Build Coastguard Worker  static_assert(!is_void_v<variant_alternative_t<_Ip, variant<_Types...>>>);
1423*58b9f456SAndroid Build Coastguard Worker  return __generic_get_if<_Ip>(__v);
1424*58b9f456SAndroid Build Coastguard Worker}
1425*58b9f456SAndroid Build Coastguard Worker
1426*58b9f456SAndroid Build Coastguard Workertemplate <size_t _Ip, class... _Types>
1427*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
1428*58b9f456SAndroid Build Coastguard Workerconstexpr add_pointer_t<const variant_alternative_t<_Ip, variant<_Types...>>>
1429*58b9f456SAndroid Build Coastguard Workerget_if(const variant<_Types...>* __v) noexcept {
1430*58b9f456SAndroid Build Coastguard Worker  static_assert(_Ip < sizeof...(_Types));
1431*58b9f456SAndroid Build Coastguard Worker  static_assert(!is_void_v<variant_alternative_t<_Ip, variant<_Types...>>>);
1432*58b9f456SAndroid Build Coastguard Worker  return __generic_get_if<_Ip>(__v);
1433*58b9f456SAndroid Build Coastguard Worker}
1434*58b9f456SAndroid Build Coastguard Worker
1435*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp, class... _Types>
1436*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
1437*58b9f456SAndroid Build Coastguard Workerconstexpr add_pointer_t<_Tp>
1438*58b9f456SAndroid Build Coastguard Workerget_if(variant<_Types...>* __v) noexcept {
1439*58b9f456SAndroid Build Coastguard Worker  static_assert(!is_void_v<_Tp>);
1440*58b9f456SAndroid Build Coastguard Worker  return _VSTD::get_if<__find_exactly_one_t<_Tp, _Types...>::value>(__v);
1441*58b9f456SAndroid Build Coastguard Worker}
1442*58b9f456SAndroid Build Coastguard Worker
1443*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp, class... _Types>
1444*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
1445*58b9f456SAndroid Build Coastguard Workerconstexpr add_pointer_t<const _Tp>
1446*58b9f456SAndroid Build Coastguard Workerget_if(const variant<_Types...>* __v) noexcept {
1447*58b9f456SAndroid Build Coastguard Worker  static_assert(!is_void_v<_Tp>);
1448*58b9f456SAndroid Build Coastguard Worker  return _VSTD::get_if<__find_exactly_one_t<_Tp, _Types...>::value>(__v);
1449*58b9f456SAndroid Build Coastguard Worker}
1450*58b9f456SAndroid Build Coastguard Worker
1451*58b9f456SAndroid Build Coastguard Workertemplate <class _Operator>
1452*58b9f456SAndroid Build Coastguard Workerstruct __convert_to_bool {
1453*58b9f456SAndroid Build Coastguard Worker  template <class _T1, class _T2>
1454*58b9f456SAndroid Build Coastguard Worker  _LIBCPP_INLINE_VISIBILITY constexpr bool operator()(_T1 && __t1, _T2&& __t2) const {
1455*58b9f456SAndroid Build Coastguard Worker    static_assert(std::is_convertible<decltype(_Operator{}(_VSTD::forward<_T1>(__t1), _VSTD::forward<_T2>(__t2))), bool>::value,
1456*58b9f456SAndroid Build Coastguard Worker        "the relational operator does not return a type which is implicitly convertible to bool");
1457*58b9f456SAndroid Build Coastguard Worker    return _Operator{}(_VSTD::forward<_T1>(__t1), _VSTD::forward<_T2>(__t2));
1458*58b9f456SAndroid Build Coastguard Worker  }
1459*58b9f456SAndroid Build Coastguard Worker};
1460*58b9f456SAndroid Build Coastguard Worker
1461*58b9f456SAndroid Build Coastguard Workertemplate <class... _Types>
1462*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
1463*58b9f456SAndroid Build Coastguard Workerconstexpr bool operator==(const variant<_Types...>& __lhs,
1464*58b9f456SAndroid Build Coastguard Worker                          const variant<_Types...>& __rhs) {
1465*58b9f456SAndroid Build Coastguard Worker  using __variant_detail::__visitation::__variant;
1466*58b9f456SAndroid Build Coastguard Worker  if (__lhs.index() != __rhs.index()) return false;
1467*58b9f456SAndroid Build Coastguard Worker  if (__lhs.valueless_by_exception()) return true;
1468*58b9f456SAndroid Build Coastguard Worker  return __variant::__visit_value_at(__lhs.index(), __convert_to_bool<equal_to<>>{}, __lhs, __rhs);
1469*58b9f456SAndroid Build Coastguard Worker}
1470*58b9f456SAndroid Build Coastguard Worker
1471*58b9f456SAndroid Build Coastguard Workertemplate <class... _Types>
1472*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
1473*58b9f456SAndroid Build Coastguard Workerconstexpr bool operator!=(const variant<_Types...>& __lhs,
1474*58b9f456SAndroid Build Coastguard Worker                          const variant<_Types...>& __rhs) {
1475*58b9f456SAndroid Build Coastguard Worker  using __variant_detail::__visitation::__variant;
1476*58b9f456SAndroid Build Coastguard Worker  if (__lhs.index() != __rhs.index()) return true;
1477*58b9f456SAndroid Build Coastguard Worker  if (__lhs.valueless_by_exception()) return false;
1478*58b9f456SAndroid Build Coastguard Worker  return __variant::__visit_value_at(
1479*58b9f456SAndroid Build Coastguard Worker      __lhs.index(), __convert_to_bool<not_equal_to<>>{}, __lhs, __rhs);
1480*58b9f456SAndroid Build Coastguard Worker}
1481*58b9f456SAndroid Build Coastguard Worker
1482*58b9f456SAndroid Build Coastguard Workertemplate <class... _Types>
1483*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
1484*58b9f456SAndroid Build Coastguard Workerconstexpr bool operator<(const variant<_Types...>& __lhs,
1485*58b9f456SAndroid Build Coastguard Worker                         const variant<_Types...>& __rhs) {
1486*58b9f456SAndroid Build Coastguard Worker  using __variant_detail::__visitation::__variant;
1487*58b9f456SAndroid Build Coastguard Worker  if (__rhs.valueless_by_exception()) return false;
1488*58b9f456SAndroid Build Coastguard Worker  if (__lhs.valueless_by_exception()) return true;
1489*58b9f456SAndroid Build Coastguard Worker  if (__lhs.index() < __rhs.index()) return true;
1490*58b9f456SAndroid Build Coastguard Worker  if (__lhs.index() > __rhs.index()) return false;
1491*58b9f456SAndroid Build Coastguard Worker  return __variant::__visit_value_at(__lhs.index(), __convert_to_bool<less<>>{}, __lhs, __rhs);
1492*58b9f456SAndroid Build Coastguard Worker}
1493*58b9f456SAndroid Build Coastguard Worker
1494*58b9f456SAndroid Build Coastguard Workertemplate <class... _Types>
1495*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
1496*58b9f456SAndroid Build Coastguard Workerconstexpr bool operator>(const variant<_Types...>& __lhs,
1497*58b9f456SAndroid Build Coastguard Worker                         const variant<_Types...>& __rhs) {
1498*58b9f456SAndroid Build Coastguard Worker  using __variant_detail::__visitation::__variant;
1499*58b9f456SAndroid Build Coastguard Worker  if (__lhs.valueless_by_exception()) return false;
1500*58b9f456SAndroid Build Coastguard Worker  if (__rhs.valueless_by_exception()) return true;
1501*58b9f456SAndroid Build Coastguard Worker  if (__lhs.index() > __rhs.index()) return true;
1502*58b9f456SAndroid Build Coastguard Worker  if (__lhs.index() < __rhs.index()) return false;
1503*58b9f456SAndroid Build Coastguard Worker  return __variant::__visit_value_at(__lhs.index(), __convert_to_bool<greater<>>{}, __lhs, __rhs);
1504*58b9f456SAndroid Build Coastguard Worker}
1505*58b9f456SAndroid Build Coastguard Worker
1506*58b9f456SAndroid Build Coastguard Workertemplate <class... _Types>
1507*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
1508*58b9f456SAndroid Build Coastguard Workerconstexpr bool operator<=(const variant<_Types...>& __lhs,
1509*58b9f456SAndroid Build Coastguard Worker                          const variant<_Types...>& __rhs) {
1510*58b9f456SAndroid Build Coastguard Worker  using __variant_detail::__visitation::__variant;
1511*58b9f456SAndroid Build Coastguard Worker  if (__lhs.valueless_by_exception()) return true;
1512*58b9f456SAndroid Build Coastguard Worker  if (__rhs.valueless_by_exception()) return false;
1513*58b9f456SAndroid Build Coastguard Worker  if (__lhs.index() < __rhs.index()) return true;
1514*58b9f456SAndroid Build Coastguard Worker  if (__lhs.index() > __rhs.index()) return false;
1515*58b9f456SAndroid Build Coastguard Worker  return __variant::__visit_value_at(
1516*58b9f456SAndroid Build Coastguard Worker      __lhs.index(), __convert_to_bool<less_equal<>>{}, __lhs, __rhs);
1517*58b9f456SAndroid Build Coastguard Worker}
1518*58b9f456SAndroid Build Coastguard Worker
1519*58b9f456SAndroid Build Coastguard Workertemplate <class... _Types>
1520*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
1521*58b9f456SAndroid Build Coastguard Workerconstexpr bool operator>=(const variant<_Types...>& __lhs,
1522*58b9f456SAndroid Build Coastguard Worker                          const variant<_Types...>& __rhs) {
1523*58b9f456SAndroid Build Coastguard Worker  using __variant_detail::__visitation::__variant;
1524*58b9f456SAndroid Build Coastguard Worker  if (__rhs.valueless_by_exception()) return true;
1525*58b9f456SAndroid Build Coastguard Worker  if (__lhs.valueless_by_exception()) return false;
1526*58b9f456SAndroid Build Coastguard Worker  if (__lhs.index() > __rhs.index()) return true;
1527*58b9f456SAndroid Build Coastguard Worker  if (__lhs.index() < __rhs.index()) return false;
1528*58b9f456SAndroid Build Coastguard Worker  return __variant::__visit_value_at(
1529*58b9f456SAndroid Build Coastguard Worker      __lhs.index(), __convert_to_bool<greater_equal<>>{}, __lhs, __rhs);
1530*58b9f456SAndroid Build Coastguard Worker}
1531*58b9f456SAndroid Build Coastguard Worker
1532*58b9f456SAndroid Build Coastguard Workertemplate <class _Visitor, class... _Vs>
1533*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
1534*58b9f456SAndroid Build Coastguard Worker_LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS
1535*58b9f456SAndroid Build Coastguard Workerconstexpr decltype(auto) visit(_Visitor&& __visitor, _Vs&&... __vs) {
1536*58b9f456SAndroid Build Coastguard Worker  using __variant_detail::__visitation::__variant;
1537*58b9f456SAndroid Build Coastguard Worker  bool __results[] = {__vs.valueless_by_exception()...};
1538*58b9f456SAndroid Build Coastguard Worker  for (bool __result : __results) {
1539*58b9f456SAndroid Build Coastguard Worker    if (__result) {
1540*58b9f456SAndroid Build Coastguard Worker      __throw_bad_variant_access();
1541*58b9f456SAndroid Build Coastguard Worker    }
1542*58b9f456SAndroid Build Coastguard Worker  }
1543*58b9f456SAndroid Build Coastguard Worker  return __variant::__visit_value(_VSTD::forward<_Visitor>(__visitor),
1544*58b9f456SAndroid Build Coastguard Worker                                  _VSTD::forward<_Vs>(__vs)...);
1545*58b9f456SAndroid Build Coastguard Worker}
1546*58b9f456SAndroid Build Coastguard Worker
1547*58b9f456SAndroid Build Coastguard Workerstruct _LIBCPP_TEMPLATE_VIS monostate {};
1548*58b9f456SAndroid Build Coastguard Worker
1549*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
1550*58b9f456SAndroid Build Coastguard Workerconstexpr bool operator<(monostate, monostate) noexcept { return false; }
1551*58b9f456SAndroid Build Coastguard Worker
1552*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
1553*58b9f456SAndroid Build Coastguard Workerconstexpr bool operator>(monostate, monostate) noexcept { return false; }
1554*58b9f456SAndroid Build Coastguard Worker
1555*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
1556*58b9f456SAndroid Build Coastguard Workerconstexpr bool operator<=(monostate, monostate) noexcept { return true; }
1557*58b9f456SAndroid Build Coastguard Worker
1558*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
1559*58b9f456SAndroid Build Coastguard Workerconstexpr bool operator>=(monostate, monostate) noexcept { return true; }
1560*58b9f456SAndroid Build Coastguard Worker
1561*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
1562*58b9f456SAndroid Build Coastguard Workerconstexpr bool operator==(monostate, monostate) noexcept { return true; }
1563*58b9f456SAndroid Build Coastguard Worker
1564*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
1565*58b9f456SAndroid Build Coastguard Workerconstexpr bool operator!=(monostate, monostate) noexcept { return false; }
1566*58b9f456SAndroid Build Coastguard Worker
1567*58b9f456SAndroid Build Coastguard Workertemplate <class... _Types>
1568*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
1569*58b9f456SAndroid Build Coastguard Workerauto swap(variant<_Types...>& __lhs,
1570*58b9f456SAndroid Build Coastguard Worker          variant<_Types...>& __rhs) noexcept(noexcept(__lhs.swap(__rhs)))
1571*58b9f456SAndroid Build Coastguard Worker    -> decltype(__lhs.swap(__rhs)) {
1572*58b9f456SAndroid Build Coastguard Worker  __lhs.swap(__rhs);
1573*58b9f456SAndroid Build Coastguard Worker}
1574*58b9f456SAndroid Build Coastguard Worker
1575*58b9f456SAndroid Build Coastguard Workertemplate <class... _Types>
1576*58b9f456SAndroid Build Coastguard Workerstruct _LIBCPP_TEMPLATE_VIS hash<
1577*58b9f456SAndroid Build Coastguard Worker    __enable_hash_helper<variant<_Types...>, remove_const_t<_Types>...>> {
1578*58b9f456SAndroid Build Coastguard Worker  using argument_type = variant<_Types...>;
1579*58b9f456SAndroid Build Coastguard Worker  using result_type = size_t;
1580*58b9f456SAndroid Build Coastguard Worker
1581*58b9f456SAndroid Build Coastguard Worker  inline _LIBCPP_INLINE_VISIBILITY
1582*58b9f456SAndroid Build Coastguard Worker  result_type operator()(const argument_type& __v) const {
1583*58b9f456SAndroid Build Coastguard Worker    using __variant_detail::__visitation::__variant;
1584*58b9f456SAndroid Build Coastguard Worker    size_t __res =
1585*58b9f456SAndroid Build Coastguard Worker        __v.valueless_by_exception()
1586*58b9f456SAndroid Build Coastguard Worker               ? 299792458 // Random value chosen by the universe upon creation
1587*58b9f456SAndroid Build Coastguard Worker               : __variant::__visit_alt(
1588*58b9f456SAndroid Build Coastguard Worker                     [](const auto& __alt) {
1589*58b9f456SAndroid Build Coastguard Worker                       using __alt_type = __uncvref_t<decltype(__alt)>;
1590*58b9f456SAndroid Build Coastguard Worker                       using __value_type = remove_const_t<
1591*58b9f456SAndroid Build Coastguard Worker                         typename __alt_type::__value_type>;
1592*58b9f456SAndroid Build Coastguard Worker                       return hash<__value_type>{}(__alt.__value);
1593*58b9f456SAndroid Build Coastguard Worker                     },
1594*58b9f456SAndroid Build Coastguard Worker                     __v);
1595*58b9f456SAndroid Build Coastguard Worker    return __hash_combine(__res, hash<size_t>{}(__v.index()));
1596*58b9f456SAndroid Build Coastguard Worker  }
1597*58b9f456SAndroid Build Coastguard Worker};
1598*58b9f456SAndroid Build Coastguard Worker
1599*58b9f456SAndroid Build Coastguard Workertemplate <>
1600*58b9f456SAndroid Build Coastguard Workerstruct _LIBCPP_TEMPLATE_VIS hash<monostate> {
1601*58b9f456SAndroid Build Coastguard Worker  using argument_type = monostate;
1602*58b9f456SAndroid Build Coastguard Worker  using result_type = size_t;
1603*58b9f456SAndroid Build Coastguard Worker
1604*58b9f456SAndroid Build Coastguard Worker  inline _LIBCPP_INLINE_VISIBILITY
1605*58b9f456SAndroid Build Coastguard Worker  result_type operator()(const argument_type&) const _NOEXCEPT {
1606*58b9f456SAndroid Build Coastguard Worker    return 66740831; // return a fundamentally attractive random value.
1607*58b9f456SAndroid Build Coastguard Worker  }
1608*58b9f456SAndroid Build Coastguard Worker};
1609*58b9f456SAndroid Build Coastguard Worker
1610*58b9f456SAndroid Build Coastguard Worker#endif  // _LIBCPP_STD_VER > 14
1611*58b9f456SAndroid Build Coastguard Worker
1612*58b9f456SAndroid Build Coastguard Worker_LIBCPP_END_NAMESPACE_STD
1613*58b9f456SAndroid Build Coastguard Worker
1614*58b9f456SAndroid Build Coastguard Worker_LIBCPP_POP_MACROS
1615*58b9f456SAndroid Build Coastguard Worker
1616*58b9f456SAndroid Build Coastguard Worker#endif  // _LIBCPP_VARIANT
1617