libstdc++
variant
Go to the documentation of this file.
1 // <variant> -*- C++ -*-
2 
3 // Copyright (C) 2016-2020 Free Software Foundation, Inc.
4 //
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 3, or (at your option)
9 // any later version.
10 
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 
16 // Under Section 7 of GPL version 3, you are granted additional
17 // permissions described in the GCC Runtime Library Exception, version
18 // 3.1, as published by the Free Software Foundation.
19 
20 // You should have received a copy of the GNU General Public License and
21 // a copy of the GCC Runtime Library Exception along with this program;
22 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 // <http://www.gnu.org/licenses/>.
24 
25 /** @file variant
26  * This is the <variant> C++ Library header.
27  */
28 
29 #ifndef _GLIBCXX_VARIANT
30 #define _GLIBCXX_VARIANT 1
31 
32 #pragma GCC system_header
33 
34 #if __cplusplus >= 201703L
35 
36 #include <type_traits>
37 #include <utility>
39 #include <bits/functexcept.h>
40 #include <bits/move.h>
41 #include <bits/functional_hash.h>
42 #include <bits/invoke.h>
43 #include <ext/aligned_buffer.h>
44 #include <bits/parse_numbers.h>
47 #include <bits/stl_construct.h>
48 #if __cplusplus > 201703L
49 # include <compare>
50 #endif
51 
52 namespace std _GLIBCXX_VISIBILITY(default)
53 {
54 _GLIBCXX_BEGIN_NAMESPACE_VERSION
55 
56 namespace __detail
57 {
58 namespace __variant
59 {
60  template<size_t _Np, typename... _Types>
61  struct _Nth_type;
62 
63  template<size_t _Np, typename _First, typename... _Rest>
64  struct _Nth_type<_Np, _First, _Rest...>
65  : _Nth_type<_Np-1, _Rest...> { };
66 
67  template<typename _First, typename... _Rest>
68  struct _Nth_type<0, _First, _Rest...>
69  { using type = _First; };
70 
71 } // namespace __variant
72 } // namespace __detail
73 
74 #define __cpp_lib_variant 201606L
75 
76  template<typename... _Types> class tuple;
77  template<typename... _Types> class variant;
78  template <typename> struct hash;
79 
80  template<typename _Variant>
81  struct variant_size;
82 
83  template<typename _Variant>
84  struct variant_size<const _Variant> : variant_size<_Variant> {};
85 
86  template<typename _Variant>
87  struct variant_size<volatile _Variant> : variant_size<_Variant> {};
88 
89  template<typename _Variant>
90  struct variant_size<const volatile _Variant> : variant_size<_Variant> {};
91 
92  template<typename... _Types>
93  struct variant_size<variant<_Types...>>
94  : std::integral_constant<size_t, sizeof...(_Types)> {};
95 
96  template<typename _Variant>
97  inline constexpr size_t variant_size_v = variant_size<_Variant>::value;
98 
99  template<size_t _Np, typename _Variant>
100  struct variant_alternative;
101 
102  template<size_t _Np, typename _First, typename... _Rest>
103  struct variant_alternative<_Np, variant<_First, _Rest...>>
104  : variant_alternative<_Np-1, variant<_Rest...>> {};
105 
106  template<typename _First, typename... _Rest>
107  struct variant_alternative<0, variant<_First, _Rest...>>
108  { using type = _First; };
109 
110  template<size_t _Np, typename _Variant>
111  using variant_alternative_t =
112  typename variant_alternative<_Np, _Variant>::type;
113 
114  template<size_t _Np, typename _Variant>
115  struct variant_alternative<_Np, const _Variant>
116  { using type = add_const_t<variant_alternative_t<_Np, _Variant>>; };
117 
118  template<size_t _Np, typename _Variant>
119  struct variant_alternative<_Np, volatile _Variant>
120  { using type = add_volatile_t<variant_alternative_t<_Np, _Variant>>; };
121 
122  template<size_t _Np, typename _Variant>
123  struct variant_alternative<_Np, const volatile _Variant>
124  { using type = add_cv_t<variant_alternative_t<_Np, _Variant>>; };
125 
126  inline constexpr size_t variant_npos = -1;
127 
128  template<size_t _Np, typename... _Types>
129  constexpr variant_alternative_t<_Np, variant<_Types...>>&
130  get(variant<_Types...>&);
131 
132  template<size_t _Np, typename... _Types>
133  constexpr variant_alternative_t<_Np, variant<_Types...>>&&
134  get(variant<_Types...>&&);
135 
136  template<size_t _Np, typename... _Types>
137  constexpr variant_alternative_t<_Np, variant<_Types...>> const&
138  get(const variant<_Types...>&);
139 
140  template<size_t _Np, typename... _Types>
141  constexpr variant_alternative_t<_Np, variant<_Types...>> const&&
142  get(const variant<_Types...>&&);
143 
144  template<typename _Result_type, typename _Visitor, typename... _Variants>
145  constexpr decltype(auto)
146  __do_visit(_Visitor&& __visitor, _Variants&&... __variants);
147 
148  template <typename... _Types, typename _Tp>
149  decltype(auto)
150  __variant_cast(_Tp&& __rhs)
151  {
152  if constexpr (is_lvalue_reference_v<_Tp>)
153  {
154  if constexpr (is_const_v<remove_reference_t<_Tp>>)
155  return static_cast<const variant<_Types...>&>(__rhs);
156  else
157  return static_cast<variant<_Types...>&>(__rhs);
158  }
159  else
160  return static_cast<variant<_Types...>&&>(__rhs);
161  }
162 
163 namespace __detail
164 {
165 namespace __variant
166 {
167  // Returns the first appearence of _Tp in _Types.
168  // Returns sizeof...(_Types) if _Tp is not in _Types.
169  template<typename _Tp, typename... _Types>
170  struct __index_of : std::integral_constant<size_t, 0> {};
171 
172  template<typename _Tp, typename... _Types>
173  inline constexpr size_t __index_of_v = __index_of<_Tp, _Types...>::value;
174 
175  template<typename _Tp, typename _First, typename... _Rest>
176  struct __index_of<_Tp, _First, _Rest...> :
177  std::integral_constant<size_t, is_same_v<_Tp, _First>
178  ? 0 : __index_of_v<_Tp, _Rest...> + 1> {};
179 
180  // used for raw visitation
181  struct __variant_cookie {};
182  // used for raw visitation with indices passed in
183  struct __variant_idx_cookie { using type = __variant_idx_cookie; };
184  // Used to enable deduction (and same-type checking) for std::visit:
185  template<typename> struct __deduce_visit_result { };
186 
187  // Visit variants that might be valueless.
188  template<typename _Visitor, typename... _Variants>
189  constexpr void
190  __raw_visit(_Visitor&& __visitor, _Variants&&... __variants)
191  {
192  std::__do_visit<__variant_cookie>(std::forward<_Visitor>(__visitor),
193  std::forward<_Variants>(__variants)...);
194  }
195 
196  // Visit variants that might be valueless, passing indices to the visitor.
197  template<typename _Visitor, typename... _Variants>
198  constexpr void
199  __raw_idx_visit(_Visitor&& __visitor, _Variants&&... __variants)
200  {
201  std::__do_visit<__variant_idx_cookie>(std::forward<_Visitor>(__visitor),
202  std::forward<_Variants>(__variants)...);
203  }
204 
205  // _Uninitialized<T> is guaranteed to be a trivially destructible type,
206  // even if T is not.
207  template<typename _Type, bool = std::is_trivially_destructible_v<_Type>>
208  struct _Uninitialized;
209 
210  template<typename _Type>
211  struct _Uninitialized<_Type, true>
212  {
213  template<typename... _Args>
214  constexpr
215  _Uninitialized(in_place_index_t<0>, _Args&&... __args)
216  : _M_storage(std::forward<_Args>(__args)...)
217  { }
218 
219  constexpr const _Type& _M_get() const & noexcept
220  { return _M_storage; }
221 
222  constexpr _Type& _M_get() & noexcept
223  { return _M_storage; }
224 
225  constexpr const _Type&& _M_get() const && noexcept
226  { return std::move(_M_storage); }
227 
228  constexpr _Type&& _M_get() && noexcept
229  { return std::move(_M_storage); }
230 
231  _Type _M_storage;
232  };
233 
234  template<typename _Type>
235  struct _Uninitialized<_Type, false>
236  {
237  template<typename... _Args>
238  constexpr
239  _Uninitialized(in_place_index_t<0>, _Args&&... __args)
240  {
241  ::new ((void*)std::addressof(_M_storage))
242  _Type(std::forward<_Args>(__args)...);
243  }
244 
245  const _Type& _M_get() const & noexcept
246  { return *_M_storage._M_ptr(); }
247 
248  _Type& _M_get() & noexcept
249  { return *_M_storage._M_ptr(); }
250 
251  const _Type&& _M_get() const && noexcept
252  { return std::move(*_M_storage._M_ptr()); }
253 
254  _Type&& _M_get() && noexcept
255  { return std::move(*_M_storage._M_ptr()); }
256 
257  __gnu_cxx::__aligned_membuf<_Type> _M_storage;
258  };
259 
260  template<typename _Union>
261  constexpr decltype(auto)
262  __get(in_place_index_t<0>, _Union&& __u) noexcept
263  { return std::forward<_Union>(__u)._M_first._M_get(); }
264 
265  template<size_t _Np, typename _Union>
266  constexpr decltype(auto)
267  __get(in_place_index_t<_Np>, _Union&& __u) noexcept
268  {
269  return __variant::__get(in_place_index<_Np-1>,
270  std::forward<_Union>(__u)._M_rest);
271  }
272 
273  // Returns the typed storage for __v.
274  template<size_t _Np, typename _Variant>
275  constexpr decltype(auto)
276  __get(_Variant&& __v) noexcept
277  {
278  return __variant::__get(std::in_place_index<_Np>,
279  std::forward<_Variant>(__v)._M_u);
280  }
281 
282  template<typename... _Types>
283  struct _Traits
284  {
285  static constexpr bool _S_default_ctor =
286  is_default_constructible_v<typename _Nth_type<0, _Types...>::type>;
287  static constexpr bool _S_copy_ctor =
288  (is_copy_constructible_v<_Types> && ...);
289  static constexpr bool _S_move_ctor =
290  (is_move_constructible_v<_Types> && ...);
291  static constexpr bool _S_copy_assign =
292  _S_copy_ctor
293  && (is_copy_assignable_v<_Types> && ...);
294  static constexpr bool _S_move_assign =
295  _S_move_ctor
296  && (is_move_assignable_v<_Types> && ...);
297 
298  static constexpr bool _S_trivial_dtor =
299  (is_trivially_destructible_v<_Types> && ...);
300  static constexpr bool _S_trivial_copy_ctor =
301  (is_trivially_copy_constructible_v<_Types> && ...);
302  static constexpr bool _S_trivial_move_ctor =
303  (is_trivially_move_constructible_v<_Types> && ...);
304  static constexpr bool _S_trivial_copy_assign =
305  _S_trivial_dtor && _S_trivial_copy_ctor
306  && (is_trivially_copy_assignable_v<_Types> && ...);
307  static constexpr bool _S_trivial_move_assign =
308  _S_trivial_dtor && _S_trivial_move_ctor
309  && (is_trivially_move_assignable_v<_Types> && ...);
310 
311  // The following nothrow traits are for non-trivial SMFs. Trivial SMFs
312  // are always nothrow.
313  static constexpr bool _S_nothrow_default_ctor =
314  is_nothrow_default_constructible_v<
315  typename _Nth_type<0, _Types...>::type>;
316  static constexpr bool _S_nothrow_copy_ctor = false;
317  static constexpr bool _S_nothrow_move_ctor =
318  (is_nothrow_move_constructible_v<_Types> && ...);
319  static constexpr bool _S_nothrow_copy_assign = false;
320  static constexpr bool _S_nothrow_move_assign =
321  _S_nothrow_move_ctor
322  && (is_nothrow_move_assignable_v<_Types> && ...);
323  };
324 
325  // Defines members and ctors.
326  template<typename... _Types>
327  union _Variadic_union { };
328 
329  template<typename _First, typename... _Rest>
330  union _Variadic_union<_First, _Rest...>
331  {
332  constexpr _Variadic_union() : _M_rest() { }
333 
334  template<typename... _Args>
335  constexpr _Variadic_union(in_place_index_t<0>, _Args&&... __args)
336  : _M_first(in_place_index<0>, std::forward<_Args>(__args)...)
337  { }
338 
339  template<size_t _Np, typename... _Args>
340  constexpr _Variadic_union(in_place_index_t<_Np>, _Args&&... __args)
341  : _M_rest(in_place_index<_Np-1>, std::forward<_Args>(__args)...)
342  { }
343 
344  _Uninitialized<_First> _M_first;
345  _Variadic_union<_Rest...> _M_rest;
346  };
347 
348  // _Never_valueless_alt is true for variant alternatives that can
349  // always be placed in a variant without it becoming valueless.
350 
351  // For suitably-small, trivially copyable types we can create temporaries
352  // on the stack and then memcpy them into place.
353  template<typename _Tp>
354  struct _Never_valueless_alt
355  : __and_<bool_constant<sizeof(_Tp) <= 256>, is_trivially_copyable<_Tp>>
356  { };
357 
358  // Specialize _Never_valueless_alt for other types which have a
359  // non-throwing and cheap move construction and move assignment operator,
360  // so that emplacing the type will provide the strong exception-safety
361  // guarantee, by creating and moving a temporary.
362  // Whether _Never_valueless_alt<T> is true or not affects the ABI of a
363  // variant using that alternative, so we can't change the value later!
364 
365  // True if every alternative in _Types... can be emplaced in a variant
366  // without it becoming valueless. If this is true, variant<_Types...>
367  // can never be valueless, which enables some minor optimizations.
368  template <typename... _Types>
369  constexpr bool __never_valueless()
370  {
371  return _Traits<_Types...>::_S_move_assign
372  && (_Never_valueless_alt<_Types>::value && ...);
373  }
374 
375  // Defines index and the dtor, possibly trivial.
376  template<bool __trivially_destructible, typename... _Types>
377  struct _Variant_storage;
378 
379  template <typename... _Types>
380  using __select_index =
381  typename __select_int::_Select_int_base<sizeof...(_Types),
382  unsigned char,
383  unsigned short>::type::value_type;
384 
385  template<typename... _Types>
386  struct _Variant_storage<false, _Types...>
387  {
388  constexpr _Variant_storage() : _M_index(variant_npos) { }
389 
390  template<size_t _Np, typename... _Args>
391  constexpr _Variant_storage(in_place_index_t<_Np>, _Args&&... __args)
392  : _M_u(in_place_index<_Np>, std::forward<_Args>(__args)...),
393  _M_index(_Np)
394  { }
395 
396  void _M_reset()
397  {
398  if (!_M_valid()) [[unlikely]]
399  return;
400 
401  std::__do_visit<void>([](auto&& __this_mem) mutable
402  {
403  std::_Destroy(std::__addressof(__this_mem));
404  }, __variant_cast<_Types...>(*this));
405 
406  _M_index = variant_npos;
407  }
408 
409  ~_Variant_storage()
410  { _M_reset(); }
411 
412  void*
413  _M_storage() const noexcept
414  {
415  return const_cast<void*>(static_cast<const void*>(
416  std::addressof(_M_u)));
417  }
418 
419  constexpr bool
420  _M_valid() const noexcept
421  {
422  if constexpr (__variant::__never_valueless<_Types...>())
423  return true;
424  return this->_M_index != __index_type(variant_npos);
425  }
426 
427  _Variadic_union<_Types...> _M_u;
428  using __index_type = __select_index<_Types...>;
429  __index_type _M_index;
430  };
431 
432  template<typename... _Types>
433  struct _Variant_storage<true, _Types...>
434  {
435  constexpr _Variant_storage() : _M_index(variant_npos) { }
436 
437  template<size_t _Np, typename... _Args>
438  constexpr _Variant_storage(in_place_index_t<_Np>, _Args&&... __args)
439  : _M_u(in_place_index<_Np>, std::forward<_Args>(__args)...),
440  _M_index(_Np)
441  { }
442 
443  void _M_reset() noexcept
444  { _M_index = variant_npos; }
445 
446  void*
447  _M_storage() const noexcept
448  {
449  return const_cast<void*>(static_cast<const void*>(
450  std::addressof(_M_u)));
451  }
452 
453  constexpr bool
454  _M_valid() const noexcept
455  {
456  if constexpr (__variant::__never_valueless<_Types...>())
457  return true;
458  return this->_M_index != __index_type(variant_npos);
459  }
460 
461  _Variadic_union<_Types...> _M_u;
462  using __index_type = __select_index<_Types...>;
463  __index_type _M_index;
464  };
465 
466  template<typename... _Types>
467  using _Variant_storage_alias =
468  _Variant_storage<_Traits<_Types...>::_S_trivial_dtor, _Types...>;
469 
470  template<typename _Tp, typename _Up>
471  void __variant_construct_single(_Tp&& __lhs, _Up&& __rhs_mem)
472  {
473  void* __storage = std::addressof(__lhs._M_u);
474  using _Type = remove_reference_t<decltype(__rhs_mem)>;
475  if constexpr (!is_same_v<_Type, __variant_cookie>)
476  ::new (__storage)
477  _Type(std::forward<decltype(__rhs_mem)>(__rhs_mem));
478  }
479 
480  template<typename... _Types, typename _Tp, typename _Up>
481  void __variant_construct(_Tp&& __lhs, _Up&& __rhs)
482  {
483  __lhs._M_index = __rhs._M_index;
484  __variant::__raw_visit([&__lhs](auto&& __rhs_mem) mutable
485  {
486  __variant_construct_single(std::forward<_Tp>(__lhs),
487  std::forward<decltype(__rhs_mem)>(__rhs_mem));
488  }, __variant_cast<_Types...>(std::forward<_Up>(__rhs)));
489  }
490 
491  // The following are (Copy|Move) (ctor|assign) layers for forwarding
492  // triviality and handling non-trivial SMF behaviors.
493 
494  template<bool, typename... _Types>
495  struct _Copy_ctor_base : _Variant_storage_alias<_Types...>
496  {
497  using _Base = _Variant_storage_alias<_Types...>;
498  using _Base::_Base;
499 
500  _Copy_ctor_base(const _Copy_ctor_base& __rhs)
501  noexcept(_Traits<_Types...>::_S_nothrow_copy_ctor)
502  {
503  __variant_construct<_Types...>(*this, __rhs);
504  }
505 
506  _Copy_ctor_base(_Copy_ctor_base&&) = default;
507  _Copy_ctor_base& operator=(const _Copy_ctor_base&) = default;
508  _Copy_ctor_base& operator=(_Copy_ctor_base&&) = default;
509  };
510 
511  template<typename... _Types>
512  struct _Copy_ctor_base<true, _Types...> : _Variant_storage_alias<_Types...>
513  {
514  using _Base = _Variant_storage_alias<_Types...>;
515  using _Base::_Base;
516  };
517 
518  template<typename... _Types>
519  using _Copy_ctor_alias =
520  _Copy_ctor_base<_Traits<_Types...>::_S_trivial_copy_ctor, _Types...>;
521 
522  template<bool, typename... _Types>
523  struct _Move_ctor_base : _Copy_ctor_alias<_Types...>
524  {
525  using _Base = _Copy_ctor_alias<_Types...>;
526  using _Base::_Base;
527 
528  _Move_ctor_base(_Move_ctor_base&& __rhs)
529  noexcept(_Traits<_Types...>::_S_nothrow_move_ctor)
530  {
531  __variant_construct<_Types...>(*this, std::move(__rhs));
532  }
533 
534  template<typename _Up>
535  void _M_destructive_move(unsigned short __rhs_index, _Up&& __rhs)
536  {
537  this->_M_reset();
538  __variant_construct_single(*this, std::forward<_Up>(__rhs));
539  this->_M_index = __rhs_index;
540  }
541 
542  template<typename _Up>
543  void _M_destructive_copy(unsigned short __rhs_index, const _Up& __rhs)
544  {
545  this->_M_reset();
546  __variant_construct_single(*this, __rhs);
547  this->_M_index = __rhs_index;
548  }
549 
550  _Move_ctor_base(const _Move_ctor_base&) = default;
551  _Move_ctor_base& operator=(const _Move_ctor_base&) = default;
552  _Move_ctor_base& operator=(_Move_ctor_base&&) = default;
553  };
554 
555  template<typename... _Types>
556  struct _Move_ctor_base<true, _Types...> : _Copy_ctor_alias<_Types...>
557  {
558  using _Base = _Copy_ctor_alias<_Types...>;
559  using _Base::_Base;
560 
561  template<typename _Up>
562  void _M_destructive_move(unsigned short __rhs_index, _Up&& __rhs)
563  {
564  this->_M_reset();
565  __variant_construct_single(*this, std::forward<_Up>(__rhs));
566  this->_M_index = __rhs_index;
567  }
568 
569  template<typename _Up>
570  void _M_destructive_copy(unsigned short __rhs_index, const _Up& __rhs)
571  {
572  this->_M_reset();
573  __variant_construct_single(*this, __rhs);
574  this->_M_index = __rhs_index;
575  }
576  };
577 
578  template<typename... _Types>
579  using _Move_ctor_alias =
580  _Move_ctor_base<_Traits<_Types...>::_S_trivial_move_ctor, _Types...>;
581 
582  template<bool, typename... _Types>
583  struct _Copy_assign_base : _Move_ctor_alias<_Types...>
584  {
585  using _Base = _Move_ctor_alias<_Types...>;
586  using _Base::_Base;
587 
588  _Copy_assign_base&
589  operator=(const _Copy_assign_base& __rhs)
590  noexcept(_Traits<_Types...>::_S_nothrow_copy_assign)
591  {
592  __variant::__raw_idx_visit(
593  [this](auto&& __rhs_mem, auto __rhs_index) mutable
594  {
595  if constexpr (__rhs_index != variant_npos)
596  {
597  if (this->_M_index == __rhs_index)
598  __variant::__get<__rhs_index>(*this) = __rhs_mem;
599  else
600  {
601  using __rhs_type = __remove_cvref_t<decltype(__rhs_mem)>;
602  if constexpr (is_nothrow_copy_constructible_v<__rhs_type>
603  || !is_nothrow_move_constructible_v<__rhs_type>)
604  // The standard says this->emplace<__rhs_type>(__rhs_mem)
605  // should be used here, but _M_destructive_copy is
606  // equivalent in this case. Either copy construction
607  // doesn't throw, so _M_destructive_copy gives strong
608  // exception safety guarantee, or both copy construction
609  // and move construction can throw, so emplace only gives
610  // basic exception safety anyway.
611  this->_M_destructive_copy(__rhs_index, __rhs_mem);
612  else
613  __variant_cast<_Types...>(*this)
614  = variant<_Types...>(std::in_place_index<__rhs_index>,
615  __rhs_mem);
616  }
617  }
618  else
619  this->_M_reset();
620  }, __variant_cast<_Types...>(__rhs));
621  return *this;
622  }
623 
624  _Copy_assign_base(const _Copy_assign_base&) = default;
625  _Copy_assign_base(_Copy_assign_base&&) = default;
626  _Copy_assign_base& operator=(_Copy_assign_base&&) = default;
627  };
628 
629  template<typename... _Types>
630  struct _Copy_assign_base<true, _Types...> : _Move_ctor_alias<_Types...>
631  {
632  using _Base = _Move_ctor_alias<_Types...>;
633  using _Base::_Base;
634  };
635 
636  template<typename... _Types>
637  using _Copy_assign_alias =
638  _Copy_assign_base<_Traits<_Types...>::_S_trivial_copy_assign, _Types...>;
639 
640  template<bool, typename... _Types>
641  struct _Move_assign_base : _Copy_assign_alias<_Types...>
642  {
643  using _Base = _Copy_assign_alias<_Types...>;
644  using _Base::_Base;
645 
646  _Move_assign_base&
647  operator=(_Move_assign_base&& __rhs)
648  noexcept(_Traits<_Types...>::_S_nothrow_move_assign)
649  {
650  __variant::__raw_idx_visit(
651  [this](auto&& __rhs_mem, auto __rhs_index) mutable
652  {
653  if constexpr (__rhs_index != variant_npos)
654  {
655  if (this->_M_index == __rhs_index)
656  __variant::__get<__rhs_index>(*this) = std::move(__rhs_mem);
657  else
658  __variant_cast<_Types...>(*this)
659  .template emplace<__rhs_index>(std::move(__rhs_mem));
660  }
661  else
662  this->_M_reset();
663  }, __variant_cast<_Types...>(__rhs));
664  return *this;
665  }
666 
667  _Move_assign_base(const _Move_assign_base&) = default;
668  _Move_assign_base(_Move_assign_base&&) = default;
669  _Move_assign_base& operator=(const _Move_assign_base&) = default;
670  };
671 
672  template<typename... _Types>
673  struct _Move_assign_base<true, _Types...> : _Copy_assign_alias<_Types...>
674  {
675  using _Base = _Copy_assign_alias<_Types...>;
676  using _Base::_Base;
677  };
678 
679  template<typename... _Types>
680  using _Move_assign_alias =
681  _Move_assign_base<_Traits<_Types...>::_S_trivial_move_assign, _Types...>;
682 
683  template<typename... _Types>
684  struct _Variant_base : _Move_assign_alias<_Types...>
685  {
686  using _Base = _Move_assign_alias<_Types...>;
687 
688  constexpr
689  _Variant_base()
690  noexcept(_Traits<_Types...>::_S_nothrow_default_ctor)
691  : _Variant_base(in_place_index<0>) { }
692 
693  template<size_t _Np, typename... _Args>
694  constexpr explicit
695  _Variant_base(in_place_index_t<_Np> __i, _Args&&... __args)
696  : _Base(__i, std::forward<_Args>(__args)...)
697  { }
698 
699  _Variant_base(const _Variant_base&) = default;
700  _Variant_base(_Variant_base&&) = default;
701  _Variant_base& operator=(const _Variant_base&) = default;
702  _Variant_base& operator=(_Variant_base&&) = default;
703  };
704 
705  // For how many times does _Tp appear in _Tuple?
706  template<typename _Tp, typename _Tuple>
707  struct __tuple_count;
708 
709  template<typename _Tp, typename _Tuple>
710  inline constexpr size_t __tuple_count_v =
711  __tuple_count<_Tp, _Tuple>::value;
712 
713  template<typename _Tp, typename... _Types>
714  struct __tuple_count<_Tp, tuple<_Types...>>
715  : integral_constant<size_t, 0> { };
716 
717  template<typename _Tp, typename _First, typename... _Rest>
718  struct __tuple_count<_Tp, tuple<_First, _Rest...>>
719  : integral_constant<
720  size_t,
721  __tuple_count_v<_Tp, tuple<_Rest...>> + is_same_v<_Tp, _First>> { };
722 
723  // TODO: Reuse this in <tuple> ?
724  template<typename _Tp, typename... _Types>
725  inline constexpr bool __exactly_once =
726  __tuple_count_v<_Tp, tuple<_Types...>> == 1;
727 
728  // Helper used to check for valid conversions that don't involve narrowing.
729  template<typename _Ti> struct _Arr { _Ti _M_x[1]; };
730 
731  // Build an imaginary function FUN(Ti) for each alternative type Ti
732  template<size_t _Ind, typename _Tp, typename _Ti,
733  bool _Ti_is_cv_bool = is_same_v<remove_cv_t<_Ti>, bool>,
734  typename = void>
735  struct _Build_FUN
736  {
737  // This function means 'using _Build_FUN<I, T, Ti>::_S_fun;' is valid,
738  // but only static functions will be considered in the call below.
739  void _S_fun();
740  };
741 
742  // ... for which Ti x[] = {std::forward<T>(t)}; is well-formed,
743  template<size_t _Ind, typename _Tp, typename _Ti>
744  struct _Build_FUN<_Ind, _Tp, _Ti, false,
745  void_t<decltype(_Arr<_Ti>{{std::declval<_Tp>()}})>>
746  {
747  // This is the FUN function for type _Ti, with index _Ind
748  static integral_constant<size_t, _Ind> _S_fun(_Ti);
749  };
750 
751  // ... and if Ti is cv bool, remove_cvref_t<T> is bool.
752  template<size_t _Ind, typename _Tp, typename _Ti>
753  struct _Build_FUN<_Ind, _Tp, _Ti, true,
754  enable_if_t<is_same_v<__remove_cvref_t<_Tp>, bool>>>
755  {
756  // This is the FUN function for when _Ti is cv bool, with index _Ind
757  static integral_constant<size_t, _Ind> _S_fun(_Ti);
758  };
759 
760  template<typename _Tp, typename _Variant,
761  typename = make_index_sequence<variant_size_v<_Variant>>>
762  struct _Build_FUNs;
763 
764  template<typename _Tp, typename... _Ti, size_t... _Ind>
765  struct _Build_FUNs<_Tp, variant<_Ti...>, index_sequence<_Ind...>>
766  : _Build_FUN<_Ind, _Tp, _Ti>...
767  {
768  using _Build_FUN<_Ind, _Tp, _Ti>::_S_fun...;
769  };
770 
771  // The index j of the overload FUN(Tj) selected by overload resolution
772  // for FUN(std::forward<_Tp>(t))
773  template<typename _Tp, typename _Variant>
774  using _FUN_type
775  = decltype(_Build_FUNs<_Tp, _Variant>::_S_fun(std::declval<_Tp>()));
776 
777  // The index selected for FUN(std::forward<T>(t)), or variant_npos if none.
778  template<typename _Tp, typename _Variant, typename = void>
779  struct __accepted_index
780  : integral_constant<size_t, variant_npos>
781  { };
782 
783  template<typename _Tp, typename _Variant>
784  struct __accepted_index<_Tp, _Variant, void_t<_FUN_type<_Tp, _Variant>>>
785  : _FUN_type<_Tp, _Variant>
786  { };
787 
788  // Returns the raw storage for __v.
789  template<typename _Variant>
790  void* __get_storage(_Variant&& __v) noexcept
791  { return __v._M_storage(); }
792 
793  template <typename _Maybe_variant_cookie, typename _Variant>
794  struct _Extra_visit_slot_needed
795  {
796  template <typename> struct _Variant_never_valueless;
797 
798  template <typename... _Types>
799  struct _Variant_never_valueless<variant<_Types...>>
800  : bool_constant<__variant::__never_valueless<_Types...>()> {};
801 
802  static constexpr bool value =
803  (is_same_v<_Maybe_variant_cookie, __variant_cookie>
804  || is_same_v<_Maybe_variant_cookie, __variant_idx_cookie>)
805  && !_Variant_never_valueless<__remove_cvref_t<_Variant>>::value;
806  };
807 
808  // Used for storing a multi-dimensional vtable.
809  template<typename _Tp, size_t... _Dimensions>
810  struct _Multi_array;
811 
812  // Partial specialization with rank zero, stores a single _Tp element.
813  template<typename _Tp>
814  struct _Multi_array<_Tp>
815  {
816  template<typename>
817  struct __untag_result
818  : false_type
819  { using element_type = _Tp; };
820 
821  template <typename... _Args>
822  struct __untag_result<const void(*)(_Args...)>
823  : false_type
824  { using element_type = void(*)(_Args...); };
825 
826  template <typename... _Args>
827  struct __untag_result<__variant_cookie(*)(_Args...)>
828  : false_type
829  { using element_type = void(*)(_Args...); };
830 
831  template <typename... _Args>
832  struct __untag_result<__variant_idx_cookie(*)(_Args...)>
833  : false_type
834  { using element_type = void(*)(_Args...); };
835 
836  template <typename _Res, typename... _Args>
837  struct __untag_result<__deduce_visit_result<_Res>(*)(_Args...)>
838  : true_type
839  { using element_type = _Res(*)(_Args...); };
840 
841  using __result_is_deduced = __untag_result<_Tp>;
842 
843  constexpr const typename __untag_result<_Tp>::element_type&
844  _M_access() const
845  { return _M_data; }
846 
847  typename __untag_result<_Tp>::element_type _M_data;
848  };
849 
850  // Partial specialization with rank >= 1.
851  template<typename _Ret,
852  typename _Visitor,
853  typename... _Variants,
854  size_t __first, size_t... __rest>
855  struct _Multi_array<_Ret(*)(_Visitor, _Variants...), __first, __rest...>
856  {
857  static constexpr size_t __index =
858  sizeof...(_Variants) - sizeof...(__rest) - 1;
859 
860  using _Variant = typename _Nth_type<__index, _Variants...>::type;
861 
862  static constexpr int __do_cookie =
863  _Extra_visit_slot_needed<_Ret, _Variant>::value ? 1 : 0;
864 
865  using _Tp = _Ret(*)(_Visitor, _Variants...);
866 
867  template<typename... _Args>
868  constexpr decltype(auto)
869  _M_access(size_t __first_index, _Args... __rest_indices) const
870  {
871  return _M_arr[__first_index + __do_cookie]
872  ._M_access(__rest_indices...);
873  }
874 
875  _Multi_array<_Tp, __rest...> _M_arr[__first + __do_cookie];
876  };
877 
878  // Creates a multi-dimensional vtable recursively.
879  //
880  // For example,
881  // visit([](auto, auto){},
882  // variant<int, char>(), // typedef'ed as V1
883  // variant<float, double, long double>()) // typedef'ed as V2
884  // will trigger instantiations of:
885  // __gen_vtable_impl<_Multi_array<void(*)(V1&&, V2&&), 2, 3>,
886  // tuple<V1&&, V2&&>, std::index_sequence<>>
887  // __gen_vtable_impl<_Multi_array<void(*)(V1&&, V2&&), 3>,
888  // tuple<V1&&, V2&&>, std::index_sequence<0>>
889  // __gen_vtable_impl<_Multi_array<void(*)(V1&&, V2&&)>,
890  // tuple<V1&&, V2&&>, std::index_sequence<0, 0>>
891  // __gen_vtable_impl<_Multi_array<void(*)(V1&&, V2&&)>,
892  // tuple<V1&&, V2&&>, std::index_sequence<0, 1>>
893  // __gen_vtable_impl<_Multi_array<void(*)(V1&&, V2&&)>,
894  // tuple<V1&&, V2&&>, std::index_sequence<0, 2>>
895  // __gen_vtable_impl<_Multi_array<void(*)(V1&&, V2&&), 3>,
896  // tuple<V1&&, V2&&>, std::index_sequence<1>>
897  // __gen_vtable_impl<_Multi_array<void(*)(V1&&, V2&&)>,
898  // tuple<V1&&, V2&&>, std::index_sequence<1, 0>>
899  // __gen_vtable_impl<_Multi_array<void(*)(V1&&, V2&&)>,
900  // tuple<V1&&, V2&&>, std::index_sequence<1, 1>>
901  // __gen_vtable_impl<_Multi_array<void(*)(V1&&, V2&&)>,
902  // tuple<V1&&, V2&&>, std::index_sequence<1, 2>>
903  // The returned multi-dimensional vtable can be fast accessed by the visitor
904  // using index calculation.
905  template<typename _Array_type, typename _Index_seq>
906  struct __gen_vtable_impl;
907 
908  // Defines the _S_apply() member that returns a _Multi_array populated
909  // with function pointers that perform the visitation expressions e(m)
910  // for each valid pack of indexes into the variant types _Variants.
911  //
912  // This partial specialization builds up the index sequences by recursively
913  // calling _S_apply() on the next specialization of __gen_vtable_impl.
914  // The base case of the recursion defines the actual function pointers.
915  template<typename _Result_type, typename _Visitor, size_t... __dimensions,
916  typename... _Variants, size_t... __indices>
917  struct __gen_vtable_impl<
918  _Multi_array<_Result_type (*)(_Visitor, _Variants...), __dimensions...>,
919  std::index_sequence<__indices...>>
920  {
921  using _Next =
922  remove_reference_t<typename _Nth_type<sizeof...(__indices),
923  _Variants...>::type>;
924  using _Array_type =
925  _Multi_array<_Result_type (*)(_Visitor, _Variants...),
926  __dimensions...>;
927 
928  static constexpr _Array_type
929  _S_apply()
930  {
931  _Array_type __vtable{};
932  _S_apply_all_alts(
933  __vtable, make_index_sequence<variant_size_v<_Next>>());
934  return __vtable;
935  }
936 
937  template<size_t... __var_indices>
938  static constexpr void
939  _S_apply_all_alts(_Array_type& __vtable,
941  {
942  if constexpr (_Extra_visit_slot_needed<_Result_type, _Next>::value)
943  (_S_apply_single_alt<true, __var_indices>(
944  __vtable._M_arr[__var_indices + 1],
945  &(__vtable._M_arr[0])), ...);
946  else
947  (_S_apply_single_alt<false, __var_indices>(
948  __vtable._M_arr[__var_indices]), ...);
949  }
950 
951  template<bool __do_cookie, size_t __index, typename _Tp>
952  static constexpr void
953  _S_apply_single_alt(_Tp& __element, _Tp* __cookie_element = nullptr)
954  {
955  if constexpr (__do_cookie)
956  {
957  __element = __gen_vtable_impl<
958  _Tp,
959  std::index_sequence<__indices..., __index>>::_S_apply();
960  *__cookie_element = __gen_vtable_impl<
961  _Tp,
962  std::index_sequence<__indices..., variant_npos>>::_S_apply();
963  }
964  else
965  {
966  __element = __gen_vtable_impl<
967  remove_reference_t<decltype(__element)>,
968  std::index_sequence<__indices..., __index>>::_S_apply();
969  }
970  }
971  };
972 
973  // This partial specialization is the base case for the recursion.
974  // It populates a _Multi_array element with the address of a function
975  // that invokes the visitor with the alternatives specified by __indices.
976  template<typename _Result_type, typename _Visitor, typename... _Variants,
977  size_t... __indices>
978  struct __gen_vtable_impl<
979  _Multi_array<_Result_type (*)(_Visitor, _Variants...)>,
980  std::index_sequence<__indices...>>
981  {
982  using _Array_type =
983  _Multi_array<_Result_type (*)(_Visitor, _Variants...)>;
984 
985  template<size_t __index, typename _Variant>
986  static constexpr decltype(auto)
987  __element_by_index_or_cookie(_Variant&& __var) noexcept
988  {
989  if constexpr (__index != variant_npos)
990  return __variant::__get<__index>(std::forward<_Variant>(__var));
991  else
992  return __variant_cookie{};
993  }
994 
995  static constexpr decltype(auto)
996  __visit_invoke(_Visitor&& __visitor, _Variants... __vars)
997  {
998  if constexpr (is_same_v<_Result_type, __variant_idx_cookie>)
999  // For raw visitation using indices, pass the indices to the visitor
1000  // and discard the return value:
1001  std::__invoke(std::forward<_Visitor>(__visitor),
1002  __element_by_index_or_cookie<__indices>(
1003  std::forward<_Variants>(__vars))...,
1004  integral_constant<size_t, __indices>()...);
1005  else if constexpr (is_same_v<_Result_type, __variant_cookie>)
1006  // For raw visitation without indices, and discard the return value:
1007  std::__invoke(std::forward<_Visitor>(__visitor),
1008  __element_by_index_or_cookie<__indices>(
1009  std::forward<_Variants>(__vars))...);
1010  else if constexpr (_Array_type::__result_is_deduced::value)
1011  // For the usual std::visit case deduce the return value:
1012  return std::__invoke(std::forward<_Visitor>(__visitor),
1013  __element_by_index_or_cookie<__indices>(
1014  std::forward<_Variants>(__vars))...);
1015  else // for std::visit<R> use INVOKE<R>
1016  return std::__invoke_r<_Result_type>(
1017  std::forward<_Visitor>(__visitor),
1018  __variant::__get<__indices>(std::forward<_Variants>(__vars))...);
1019  }
1020 
1021  static constexpr auto
1022  _S_apply()
1023  { return _Array_type{&__visit_invoke}; }
1024  };
1025 
1026  template<typename _Result_type, typename _Visitor, typename... _Variants>
1027  struct __gen_vtable
1028  {
1029  using _Array_type =
1030  _Multi_array<_Result_type (*)(_Visitor, _Variants...),
1031  variant_size_v<remove_reference_t<_Variants>>...>;
1032 
1033  static constexpr _Array_type _S_vtable
1034  = __gen_vtable_impl<_Array_type, std::index_sequence<>>::_S_apply();
1035  };
1036 
1037  template<size_t _Np, typename _Tp>
1038  struct _Base_dedup : public _Tp { };
1039 
1040  template<typename _Variant, typename __indices>
1041  struct _Variant_hash_base;
1042 
1043  template<typename... _Types, size_t... __indices>
1044  struct _Variant_hash_base<variant<_Types...>,
1045  std::index_sequence<__indices...>>
1046  : _Base_dedup<__indices, __poison_hash<remove_const_t<_Types>>>... { };
1047 
1048 } // namespace __variant
1049 } // namespace __detail
1050 
1051  template<size_t _Np, typename _Variant, typename... _Args>
1052  void __variant_construct_by_index(_Variant& __v, _Args&&... __args)
1053  {
1054  __v._M_index = _Np;
1055  auto&& __storage = __detail::__variant::__get<_Np>(__v);
1056  ::new ((void*)std::addressof(__storage))
1057  remove_reference_t<decltype(__storage)>
1058  (std::forward<_Args>(__args)...);
1059  }
1060 
1061  template<typename _Tp, typename... _Types>
1062  constexpr bool
1063  holds_alternative(const variant<_Types...>& __v) noexcept
1064  {
1065  static_assert(__detail::__variant::__exactly_once<_Tp, _Types...>,
1066  "T must occur exactly once in alternatives");
1067  return __v.index() == __detail::__variant::__index_of_v<_Tp, _Types...>;
1068  }
1069 
1070  template<typename _Tp, typename... _Types>
1071  constexpr _Tp& get(variant<_Types...>& __v)
1072  {
1073  static_assert(__detail::__variant::__exactly_once<_Tp, _Types...>,
1074  "T must occur exactly once in alternatives");
1075  static_assert(!is_void_v<_Tp>, "_Tp must not be void");
1076  return std::get<__detail::__variant::__index_of_v<_Tp, _Types...>>(__v);
1077  }
1078 
1079  template<typename _Tp, typename... _Types>
1080  constexpr _Tp&& get(variant<_Types...>&& __v)
1081  {
1082  static_assert(__detail::__variant::__exactly_once<_Tp, _Types...>,
1083  "T must occur exactly once in alternatives");
1084  static_assert(!is_void_v<_Tp>, "_Tp must not be void");
1085  return std::get<__detail::__variant::__index_of_v<_Tp, _Types...>>(
1086  std::move(__v));
1087  }
1088 
1089  template<typename _Tp, typename... _Types>
1090  constexpr const _Tp& get(const variant<_Types...>& __v)
1091  {
1092  static_assert(__detail::__variant::__exactly_once<_Tp, _Types...>,
1093  "T must occur exactly once in alternatives");
1094  static_assert(!is_void_v<_Tp>, "_Tp must not be void");
1095  return std::get<__detail::__variant::__index_of_v<_Tp, _Types...>>(__v);
1096  }
1097 
1098  template<typename _Tp, typename... _Types>
1099  constexpr const _Tp&& get(const variant<_Types...>&& __v)
1100  {
1101  static_assert(__detail::__variant::__exactly_once<_Tp, _Types...>,
1102  "T must occur exactly once in alternatives");
1103  static_assert(!is_void_v<_Tp>, "_Tp must not be void");
1104  return std::get<__detail::__variant::__index_of_v<_Tp, _Types...>>(
1105  std::move(__v));
1106  }
1107 
1108  template<size_t _Np, typename... _Types>
1109  constexpr add_pointer_t<variant_alternative_t<_Np, variant<_Types...>>>
1110  get_if(variant<_Types...>* __ptr) noexcept
1111  {
1112  using _Alternative_type = variant_alternative_t<_Np, variant<_Types...>>;
1113  static_assert(_Np < sizeof...(_Types),
1114  "The index must be in [0, number of alternatives)");
1115  static_assert(!is_void_v<_Alternative_type>, "_Tp must not be void");
1116  if (__ptr && __ptr->index() == _Np)
1117  return std::addressof(__detail::__variant::__get<_Np>(*__ptr));
1118  return nullptr;
1119  }
1120 
1121  template<size_t _Np, typename... _Types>
1122  constexpr
1123  add_pointer_t<const variant_alternative_t<_Np, variant<_Types...>>>
1124  get_if(const variant<_Types...>* __ptr) noexcept
1125  {
1126  using _Alternative_type = variant_alternative_t<_Np, variant<_Types...>>;
1127  static_assert(_Np < sizeof...(_Types),
1128  "The index must be in [0, number of alternatives)");
1129  static_assert(!is_void_v<_Alternative_type>, "_Tp must not be void");
1130  if (__ptr && __ptr->index() == _Np)
1131  return std::addressof(__detail::__variant::__get<_Np>(*__ptr));
1132  return nullptr;
1133  }
1134 
1135  template<typename _Tp, typename... _Types>
1136  constexpr add_pointer_t<_Tp>
1137  get_if(variant<_Types...>* __ptr) noexcept
1138  {
1139  static_assert(__detail::__variant::__exactly_once<_Tp, _Types...>,
1140  "T must occur exactly once in alternatives");
1141  static_assert(!is_void_v<_Tp>, "_Tp must not be void");
1142  return std::get_if<__detail::__variant::__index_of_v<_Tp, _Types...>>(
1143  __ptr);
1144  }
1145 
1146  template<typename _Tp, typename... _Types>
1147  constexpr add_pointer_t<const _Tp>
1148  get_if(const variant<_Types...>* __ptr) noexcept
1149  {
1150  static_assert(__detail::__variant::__exactly_once<_Tp, _Types...>,
1151  "T must occur exactly once in alternatives");
1152  static_assert(!is_void_v<_Tp>, "_Tp must not be void");
1153  return std::get_if<__detail::__variant::__index_of_v<_Tp, _Types...>>(
1154  __ptr);
1155  }
1156 
1157  struct monostate { };
1158 
1159 #define _VARIANT_RELATION_FUNCTION_TEMPLATE(__OP, __NAME) \
1160  template<typename... _Types> \
1161  constexpr bool operator __OP(const variant<_Types...>& __lhs, \
1162  const variant<_Types...>& __rhs) \
1163  { \
1164  bool __ret = true; \
1165  __detail::__variant::__raw_idx_visit( \
1166  [&__ret, &__lhs] (auto&& __rhs_mem, auto __rhs_index) mutable \
1167  { \
1168  if constexpr (__rhs_index != variant_npos) \
1169  { \
1170  if (__lhs.index() == __rhs_index) \
1171  { \
1172  auto& __this_mem = std::get<__rhs_index>(__lhs); \
1173  __ret = __this_mem __OP __rhs_mem; \
1174  } \
1175  else \
1176  __ret = (__lhs.index() + 1) __OP (__rhs_index + 1); \
1177  } \
1178  else \
1179  __ret = (__lhs.index() + 1) __OP (__rhs_index + 1); \
1180  }, __rhs); \
1181  return __ret; \
1182  }
1183 
1184  _VARIANT_RELATION_FUNCTION_TEMPLATE(<, less)
1185  _VARIANT_RELATION_FUNCTION_TEMPLATE(<=, less_equal)
1186  _VARIANT_RELATION_FUNCTION_TEMPLATE(==, equal)
1187  _VARIANT_RELATION_FUNCTION_TEMPLATE(!=, not_equal)
1188  _VARIANT_RELATION_FUNCTION_TEMPLATE(>=, greater_equal)
1189  _VARIANT_RELATION_FUNCTION_TEMPLATE(>, greater)
1190 
1191 #undef _VARIANT_RELATION_FUNCTION_TEMPLATE
1192 
1193  constexpr bool operator==(monostate, monostate) noexcept { return true; }
1194 
1195 #ifdef __cpp_lib_three_way_comparison
1196  template<typename... _Types>
1197  requires (three_way_comparable<_Types> && ...)
1198  constexpr
1199  common_comparison_category_t<compare_three_way_result_t<_Types>...>
1200  operator<=>(const variant<_Types...>& __v, const variant<_Types...>& __w)
1201  {
1202  common_comparison_category_t<compare_three_way_result_t<_Types>...> __ret
1203  = strong_ordering::equal;
1204 
1205  __detail::__variant::__raw_idx_visit(
1206  [&__ret, &__v] (auto&& __w_mem, auto __w_index) mutable
1207  {
1208  if constexpr (__w_index != variant_npos)
1209  {
1210  if (__v.index() == __w_index)
1211  {
1212  auto& __this_mem = std::get<__w_index>(__v);
1213  __ret = __this_mem <=> __w_mem;
1214  return;
1215  }
1216  }
1217  __ret = (__v.index() + 1) <=> (__w_index + 1);
1218  }, __w);
1219  return __ret;
1220  }
1221 
1222  constexpr strong_ordering
1223  operator<=>(monostate, monostate) noexcept { return strong_ordering::equal; }
1224 #else
1225  constexpr bool operator!=(monostate, monostate) noexcept { return false; }
1226  constexpr bool operator<(monostate, monostate) noexcept { return false; }
1227  constexpr bool operator>(monostate, monostate) noexcept { return false; }
1228  constexpr bool operator<=(monostate, monostate) noexcept { return true; }
1229  constexpr bool operator>=(monostate, monostate) noexcept { return true; }
1230 #endif
1231 
1232  template<typename _Visitor, typename... _Variants>
1233  constexpr decltype(auto) visit(_Visitor&&, _Variants&&...);
1234 
1235  template<typename... _Types>
1236  inline enable_if_t<(is_move_constructible_v<_Types> && ...)
1237  && (is_swappable_v<_Types> && ...)>
1238  swap(variant<_Types...>& __lhs, variant<_Types...>& __rhs)
1239  noexcept(noexcept(__lhs.swap(__rhs)))
1240  { __lhs.swap(__rhs); }
1241 
1242  template<typename... _Types>
1243  enable_if_t<!((is_move_constructible_v<_Types> && ...)
1244  && (is_swappable_v<_Types> && ...))>
1245  swap(variant<_Types...>&, variant<_Types...>&) = delete;
1246 
1247  class bad_variant_access : public exception
1248  {
1249  public:
1250  bad_variant_access() noexcept { }
1251 
1252  const char* what() const noexcept override
1253  { return _M_reason; }
1254 
1255  private:
1256  bad_variant_access(const char* __reason) noexcept : _M_reason(__reason) { }
1257 
1258  // Must point to a string with static storage duration:
1259  const char* _M_reason = "bad variant access";
1260 
1261  friend void __throw_bad_variant_access(const char* __what);
1262  };
1263 
1264  // Must only be called with a string literal
1265  inline void
1266  __throw_bad_variant_access(const char* __what)
1267  { _GLIBCXX_THROW_OR_ABORT(bad_variant_access(__what)); }
1268 
1269  inline void
1270  __throw_bad_variant_access(bool __valueless)
1271  {
1272  if (__valueless) [[__unlikely__]]
1273  __throw_bad_variant_access("std::get: variant is valueless");
1274  else
1275  __throw_bad_variant_access("std::get: wrong index for variant");
1276  }
1277 
1278  template<typename... _Types>
1279  class variant
1280  : private __detail::__variant::_Variant_base<_Types...>,
1281  private _Enable_default_constructor<
1282  __detail::__variant::_Traits<_Types...>::_S_default_ctor,
1283  variant<_Types...>>,
1284  private _Enable_copy_move<
1285  __detail::__variant::_Traits<_Types...>::_S_copy_ctor,
1286  __detail::__variant::_Traits<_Types...>::_S_copy_assign,
1287  __detail::__variant::_Traits<_Types...>::_S_move_ctor,
1288  __detail::__variant::_Traits<_Types...>::_S_move_assign,
1289  variant<_Types...>>
1290  {
1291  private:
1292  template <typename... _UTypes, typename _Tp>
1293  friend decltype(auto) __variant_cast(_Tp&&);
1294  template<size_t _Np, typename _Variant, typename... _Args>
1295  friend void __variant_construct_by_index(_Variant& __v,
1296  _Args&&... __args);
1297 
1298  static_assert(sizeof...(_Types) > 0,
1299  "variant must have at least one alternative");
1300  static_assert(!(std::is_reference_v<_Types> || ...),
1301  "variant must have no reference alternative");
1302  static_assert(!(std::is_void_v<_Types> || ...),
1303  "variant must have no void alternative");
1304 
1305  using _Base = __detail::__variant::_Variant_base<_Types...>;
1306  using _Default_ctor_enabler =
1307  _Enable_default_constructor<
1308  __detail::__variant::_Traits<_Types...>::_S_default_ctor,
1309  variant<_Types...>>;
1310 
1311  template<typename _Tp>
1312  static constexpr bool __not_self
1313  = !is_same_v<__remove_cvref_t<_Tp>, variant>;
1314 
1315  template<typename _Tp>
1316  static constexpr bool
1317  __exactly_once = __detail::__variant::__exactly_once<_Tp, _Types...>;
1318 
1319  template<typename _Tp>
1320  static constexpr size_t __accepted_index
1321  = __detail::__variant::__accepted_index<_Tp, variant>::value;
1322 
1323  template<size_t _Np, typename = enable_if_t<(_Np < sizeof...(_Types))>>
1324  using __to_type = variant_alternative_t<_Np, variant>;
1325 
1326  template<typename _Tp, typename = enable_if_t<__not_self<_Tp>>>
1327  using __accepted_type = __to_type<__accepted_index<_Tp>>;
1328 
1329  template<typename _Tp>
1330  static constexpr size_t __index_of =
1331  __detail::__variant::__index_of_v<_Tp, _Types...>;
1332 
1333  using _Traits = __detail::__variant::_Traits<_Types...>;
1334 
1335  template<typename _Tp>
1336  struct __is_in_place_tag : false_type { };
1337  template<typename _Tp>
1338  struct __is_in_place_tag<in_place_type_t<_Tp>> : true_type { };
1339  template<size_t _Np>
1340  struct __is_in_place_tag<in_place_index_t<_Np>> : true_type { };
1341 
1342  template<typename _Tp>
1343  static constexpr bool __not_in_place_tag
1344  = !__is_in_place_tag<__remove_cvref_t<_Tp>>::value;
1345 
1346  public:
1347  variant() = default;
1348  variant(const variant& __rhs) = default;
1349  variant(variant&&) = default;
1350  variant& operator=(const variant&) = default;
1351  variant& operator=(variant&&) = default;
1352  ~variant() = default;
1353 
1354  template<typename _Tp,
1355  typename = enable_if_t<sizeof...(_Types) != 0>,
1356  typename = enable_if_t<__not_in_place_tag<_Tp>>,
1357  typename _Tj = __accepted_type<_Tp&&>,
1358  typename = enable_if_t<__exactly_once<_Tj>
1359  && is_constructible_v<_Tj, _Tp>>>
1360  constexpr
1361  variant(_Tp&& __t)
1362  noexcept(is_nothrow_constructible_v<_Tj, _Tp>)
1363  : variant(in_place_index<__accepted_index<_Tp>>,
1364  std::forward<_Tp>(__t))
1365  { }
1366 
1367  template<typename _Tp, typename... _Args,
1368  typename = enable_if_t<__exactly_once<_Tp>
1369  && is_constructible_v<_Tp, _Args...>>>
1370  constexpr explicit
1371  variant(in_place_type_t<_Tp>, _Args&&... __args)
1372  : variant(in_place_index<__index_of<_Tp>>,
1373  std::forward<_Args>(__args)...)
1374  { }
1375 
1376  template<typename _Tp, typename _Up, typename... _Args,
1377  typename = enable_if_t<__exactly_once<_Tp>
1378  && is_constructible_v<_Tp,
1379  initializer_list<_Up>&, _Args...>>>
1380  constexpr explicit
1381  variant(in_place_type_t<_Tp>, initializer_list<_Up> __il,
1382  _Args&&... __args)
1383  : variant(in_place_index<__index_of<_Tp>>, __il,
1384  std::forward<_Args>(__args)...)
1385  { }
1386 
1387  template<size_t _Np, typename... _Args,
1388  typename _Tp = __to_type<_Np>,
1389  typename = enable_if_t<is_constructible_v<_Tp, _Args...>>>
1390  constexpr explicit
1391  variant(in_place_index_t<_Np>, _Args&&... __args)
1392  : _Base(in_place_index<_Np>, std::forward<_Args>(__args)...),
1393  _Default_ctor_enabler(_Enable_default_constructor_tag{})
1394  { }
1395 
1396  template<size_t _Np, typename _Up, typename... _Args,
1397  typename _Tp = __to_type<_Np>,
1398  typename = enable_if_t<is_constructible_v<_Tp,
1399  initializer_list<_Up>&,
1400  _Args...>>>
1401  constexpr explicit
1402  variant(in_place_index_t<_Np>, initializer_list<_Up> __il,
1403  _Args&&... __args)
1404  : _Base(in_place_index<_Np>, __il, std::forward<_Args>(__args)...),
1405  _Default_ctor_enabler(_Enable_default_constructor_tag{})
1406  { }
1407 
1408  template<typename _Tp>
1409  enable_if_t<__exactly_once<__accepted_type<_Tp&&>>
1410  && is_constructible_v<__accepted_type<_Tp&&>, _Tp>
1411  && is_assignable_v<__accepted_type<_Tp&&>&, _Tp>,
1412  variant&>
1413  operator=(_Tp&& __rhs)
1414  noexcept(is_nothrow_assignable_v<__accepted_type<_Tp&&>&, _Tp>
1415  && is_nothrow_constructible_v<__accepted_type<_Tp&&>, _Tp>)
1416  {
1417  constexpr auto __index = __accepted_index<_Tp>;
1418  if (index() == __index)
1419  std::get<__index>(*this) = std::forward<_Tp>(__rhs);
1420  else
1421  {
1422  using _Tj = __accepted_type<_Tp&&>;
1423  if constexpr (is_nothrow_constructible_v<_Tj, _Tp>
1424  || !is_nothrow_move_constructible_v<_Tj>)
1425  this->emplace<__index>(std::forward<_Tp>(__rhs));
1426  else
1427  operator=(variant(std::forward<_Tp>(__rhs)));
1428  }
1429  return *this;
1430  }
1431 
1432  template<typename _Tp, typename... _Args>
1433  enable_if_t<is_constructible_v<_Tp, _Args...> && __exactly_once<_Tp>,
1434  _Tp&>
1435  emplace(_Args&&... __args)
1436  {
1437  constexpr size_t __index = __index_of<_Tp>;
1438  return this->emplace<__index>(std::forward<_Args>(__args)...);
1439  }
1440 
1441  template<typename _Tp, typename _Up, typename... _Args>
1442  enable_if_t<is_constructible_v<_Tp, initializer_list<_Up>&, _Args...>
1443  && __exactly_once<_Tp>,
1444  _Tp&>
1445  emplace(initializer_list<_Up> __il, _Args&&... __args)
1446  {
1447  constexpr size_t __index = __index_of<_Tp>;
1448  return this->emplace<__index>(__il, std::forward<_Args>(__args)...);
1449  }
1450 
1451  template<size_t _Np, typename... _Args>
1452  enable_if_t<is_constructible_v<variant_alternative_t<_Np, variant>,
1453  _Args...>,
1454  variant_alternative_t<_Np, variant>&>
1455  emplace(_Args&&... __args)
1456  {
1457  static_assert(_Np < sizeof...(_Types),
1458  "The index must be in [0, number of alternatives)");
1459  using type = variant_alternative_t<_Np, variant>;
1460  // Provide the strong exception-safety guarantee when possible,
1461  // to avoid becoming valueless.
1462  if constexpr (is_nothrow_constructible_v<type, _Args...>)
1463  {
1464  this->_M_reset();
1465  __variant_construct_by_index<_Np>(*this,
1466  std::forward<_Args>(__args)...);
1467  }
1468  else if constexpr (is_scalar_v<type>)
1469  {
1470  // This might invoke a potentially-throwing conversion operator:
1471  const type __tmp(std::forward<_Args>(__args)...);
1472  // But these steps won't throw:
1473  this->_M_reset();
1474  __variant_construct_by_index<_Np>(*this, __tmp);
1475  }
1476  else if constexpr (__detail::__variant::_Never_valueless_alt<type>()
1477  && _Traits::_S_move_assign)
1478  {
1479  // This construction might throw:
1480  variant __tmp(in_place_index<_Np>,
1481  std::forward<_Args>(__args)...);
1482  // But _Never_valueless_alt<type> means this won't:
1483  *this = std::move(__tmp);
1484  }
1485  else
1486  {
1487  // This case only provides the basic exception-safety guarantee,
1488  // i.e. the variant can become valueless.
1489  this->_M_reset();
1490  __try
1491  {
1492  __variant_construct_by_index<_Np>(*this,
1493  std::forward<_Args>(__args)...);
1494  }
1495  __catch (...)
1496  {
1497  this->_M_index = variant_npos;
1498  __throw_exception_again;
1499  }
1500  }
1501  return std::get<_Np>(*this);
1502  }
1503 
1504  template<size_t _Np, typename _Up, typename... _Args>
1505  enable_if_t<is_constructible_v<variant_alternative_t<_Np, variant>,
1506  initializer_list<_Up>&, _Args...>,
1507  variant_alternative_t<_Np, variant>&>
1508  emplace(initializer_list<_Up> __il, _Args&&... __args)
1509  {
1510  static_assert(_Np < sizeof...(_Types),
1511  "The index must be in [0, number of alternatives)");
1512  using type = variant_alternative_t<_Np, variant>;
1513  // Provide the strong exception-safety guarantee when possible,
1514  // to avoid becoming valueless.
1515  if constexpr (is_nothrow_constructible_v<type,
1516  initializer_list<_Up>&,
1517  _Args...>)
1518  {
1519  this->_M_reset();
1520  __variant_construct_by_index<_Np>(*this, __il,
1521  std::forward<_Args>(__args)...);
1522  }
1523  else if constexpr (__detail::__variant::_Never_valueless_alt<type>()
1524  && _Traits::_S_move_assign)
1525  {
1526  // This construction might throw:
1527  variant __tmp(in_place_index<_Np>, __il,
1528  std::forward<_Args>(__args)...);
1529  // But _Never_valueless_alt<type> means this won't:
1530  *this = std::move(__tmp);
1531  }
1532  else
1533  {
1534  // This case only provides the basic exception-safety guarantee,
1535  // i.e. the variant can become valueless.
1536  this->_M_reset();
1537  __try
1538  {
1539  __variant_construct_by_index<_Np>(*this, __il,
1540  std::forward<_Args>(__args)...);
1541  }
1542  __catch (...)
1543  {
1544  this->_M_index = variant_npos;
1545  __throw_exception_again;
1546  }
1547  }
1548  return std::get<_Np>(*this);
1549  }
1550 
1551  constexpr bool valueless_by_exception() const noexcept
1552  { return !this->_M_valid(); }
1553 
1554  constexpr size_t index() const noexcept
1555  {
1556  using __index_type = typename _Base::__index_type;
1557  if constexpr (__detail::__variant::__never_valueless<_Types...>())
1558  return this->_M_index;
1559  else if constexpr (sizeof...(_Types) <= __index_type(-1) / 2)
1560  return make_signed_t<__index_type>(this->_M_index);
1561  else
1562  return size_t(__index_type(this->_M_index + 1)) - 1;
1563  }
1564 
1565  void
1566  swap(variant& __rhs)
1567  noexcept((__is_nothrow_swappable<_Types>::value && ...)
1568  && is_nothrow_move_constructible_v<variant>)
1569  {
1570  __detail::__variant::__raw_idx_visit(
1571  [this, &__rhs](auto&& __rhs_mem, auto __rhs_index) mutable
1572  {
1573  if constexpr (__rhs_index != variant_npos)
1574  {
1575  if (this->index() == __rhs_index)
1576  {
1577  auto& __this_mem =
1578  std::get<__rhs_index>(*this);
1579  using std::swap;
1580  swap(__this_mem, __rhs_mem);
1581  }
1582  else
1583  {
1584  if (!this->valueless_by_exception()) [[__likely__]]
1585  {
1586  auto __tmp(std::move(__rhs_mem));
1587  __rhs = std::move(*this);
1588  this->_M_destructive_move(__rhs_index,
1589  std::move(__tmp));
1590  }
1591  else
1592  {
1593  this->_M_destructive_move(__rhs_index,
1594  std::move(__rhs_mem));
1595  __rhs._M_reset();
1596  }
1597  }
1598  }
1599  else
1600  {
1601  if (!this->valueless_by_exception()) [[__likely__]]
1602  {
1603  __rhs = std::move(*this);
1604  this->_M_reset();
1605  }
1606  }
1607  }, __rhs);
1608  }
1609 
1610  private:
1611 
1612 #if defined(__clang__) && __clang_major__ <= 7
1613  public:
1614  using _Base::_M_u; // See https://bugs.llvm.org/show_bug.cgi?id=31852
1615  private:
1616 #endif
1617 
1618  template<size_t _Np, typename _Vp>
1619  friend constexpr decltype(auto)
1620  __detail::__variant::__get(_Vp&& __v) noexcept;
1621 
1622  template<typename _Vp>
1623  friend void*
1624  __detail::__variant::__get_storage(_Vp&& __v) noexcept;
1625 
1626 #define _VARIANT_RELATION_FUNCTION_TEMPLATE(__OP) \
1627  template<typename... _Tp> \
1628  friend constexpr bool \
1629  operator __OP(const variant<_Tp...>& __lhs, \
1630  const variant<_Tp...>& __rhs);
1631 
1632  _VARIANT_RELATION_FUNCTION_TEMPLATE(<)
1633  _VARIANT_RELATION_FUNCTION_TEMPLATE(<=)
1634  _VARIANT_RELATION_FUNCTION_TEMPLATE(==)
1635  _VARIANT_RELATION_FUNCTION_TEMPLATE(!=)
1636  _VARIANT_RELATION_FUNCTION_TEMPLATE(>=)
1637  _VARIANT_RELATION_FUNCTION_TEMPLATE(>)
1638 
1639 #undef _VARIANT_RELATION_FUNCTION_TEMPLATE
1640  };
1641 
1642  template<size_t _Np, typename... _Types>
1643  constexpr variant_alternative_t<_Np, variant<_Types...>>&
1644  get(variant<_Types...>& __v)
1645  {
1646  static_assert(_Np < sizeof...(_Types),
1647  "The index must be in [0, number of alternatives)");
1648  if (__v.index() != _Np)
1649  __throw_bad_variant_access(__v.valueless_by_exception());
1650  return __detail::__variant::__get<_Np>(__v);
1651  }
1652 
1653  template<size_t _Np, typename... _Types>
1654  constexpr variant_alternative_t<_Np, variant<_Types...>>&&
1655  get(variant<_Types...>&& __v)
1656  {
1657  static_assert(_Np < sizeof...(_Types),
1658  "The index must be in [0, number of alternatives)");
1659  if (__v.index() != _Np)
1660  __throw_bad_variant_access(__v.valueless_by_exception());
1661  return __detail::__variant::__get<_Np>(std::move(__v));
1662  }
1663 
1664  template<size_t _Np, typename... _Types>
1665  constexpr const variant_alternative_t<_Np, variant<_Types...>>&
1666  get(const variant<_Types...>& __v)
1667  {
1668  static_assert(_Np < sizeof...(_Types),
1669  "The index must be in [0, number of alternatives)");
1670  if (__v.index() != _Np)
1671  __throw_bad_variant_access(__v.valueless_by_exception());
1672  return __detail::__variant::__get<_Np>(__v);
1673  }
1674 
1675  template<size_t _Np, typename... _Types>
1676  constexpr const variant_alternative_t<_Np, variant<_Types...>>&&
1677  get(const variant<_Types...>&& __v)
1678  {
1679  static_assert(_Np < sizeof...(_Types),
1680  "The index must be in [0, number of alternatives)");
1681  if (__v.index() != _Np)
1682  __throw_bad_variant_access(__v.valueless_by_exception());
1683  return __detail::__variant::__get<_Np>(std::move(__v));
1684  }
1685 
1686  template<typename _Result_type, typename _Visitor, typename... _Variants>
1687  constexpr decltype(auto)
1688  __do_visit(_Visitor&& __visitor, _Variants&&... __variants)
1689  {
1690  constexpr auto& __vtable = __detail::__variant::__gen_vtable<
1691  _Result_type, _Visitor&&, _Variants&&...>::_S_vtable;
1692 
1693  auto __func_ptr = __vtable._M_access(__variants.index()...);
1694  return (*__func_ptr)(std::forward<_Visitor>(__visitor),
1695  std::forward<_Variants>(__variants)...);
1696  }
1697 
1698  template<typename _Visitor, typename... _Variants>
1699  constexpr decltype(auto)
1700  visit(_Visitor&& __visitor, _Variants&&... __variants)
1701  {
1702  if ((__variants.valueless_by_exception() || ...))
1703  __throw_bad_variant_access("std::visit: variant is valueless");
1704 
1705  using _Result_type = std::invoke_result_t<_Visitor,
1706  decltype(std::get<0>(std::declval<_Variants>()))...>;
1707 
1708  using _Tag = __detail::__variant::__deduce_visit_result<_Result_type>;
1709 
1710  return std::__do_visit<_Tag>(std::forward<_Visitor>(__visitor),
1711  std::forward<_Variants>(__variants)...);
1712  }
1713 
1714 #if __cplusplus > 201703L
1715  template<typename _Res, typename _Visitor, typename... _Variants>
1716  constexpr _Res
1717  visit(_Visitor&& __visitor, _Variants&&... __variants)
1718  {
1719  if ((__variants.valueless_by_exception() || ...))
1720  __throw_bad_variant_access("std::visit<R>: variant is valueless");
1721 
1722  return std::__do_visit<_Res>(std::forward<_Visitor>(__visitor),
1723  std::forward<_Variants>(__variants)...);
1724  }
1725 #endif
1726 
1727  template<bool, typename... _Types>
1728  struct __variant_hash_call_base_impl
1729  {
1730  size_t
1731  operator()(const variant<_Types...>& __t) const
1732  noexcept((is_nothrow_invocable_v<hash<decay_t<_Types>>, _Types> && ...))
1733  {
1734  size_t __ret;
1735  __detail::__variant::__raw_visit(
1736  [&__t, &__ret](auto&& __t_mem) mutable
1737  {
1738  using _Type = __remove_cvref_t<decltype(__t_mem)>;
1739  if constexpr (!is_same_v<_Type,
1740  __detail::__variant::__variant_cookie>)
1741  __ret = std::hash<size_t>{}(__t.index())
1742  + std::hash<_Type>{}(__t_mem);
1743  else
1744  __ret = std::hash<size_t>{}(__t.index());
1745  }, __t);
1746  return __ret;
1747  }
1748  };
1749 
1750  template<typename... _Types>
1751  struct __variant_hash_call_base_impl<false, _Types...> {};
1752 
1753  template<typename... _Types>
1754  using __variant_hash_call_base =
1755  __variant_hash_call_base_impl<(__poison_hash<remove_const_t<_Types>>::
1756  __enable_hash_call &&...), _Types...>;
1757 
1758  template<typename... _Types>
1759  struct hash<variant<_Types...>>
1760  : private __detail::__variant::_Variant_hash_base<
1761  variant<_Types...>, std::index_sequence_for<_Types...>>,
1762  public __variant_hash_call_base<_Types...>
1763  {
1764  using result_type [[__deprecated__]] = size_t;
1765  using argument_type [[__deprecated__]] = variant<_Types...>;
1766  };
1767 
1768  template<>
1769  struct hash<monostate>
1770  {
1771  using result_type [[__deprecated__]] = size_t;
1772  using argument_type [[__deprecated__]] = monostate;
1773 
1774  size_t
1775  operator()(const monostate&) const noexcept
1776  {
1777  constexpr size_t __magic_monostate_hash = -7777;
1778  return __magic_monostate_hash;
1779  }
1780  };
1781 
1782  template<typename... _Types>
1783  struct __is_fast_hash<hash<variant<_Types...>>>
1784  : bool_constant<(__is_fast_hash<_Types>::value && ...)>
1785  { };
1786 
1787 _GLIBCXX_END_NAMESPACE_VERSION
1788 } // namespace std
1789 
1790 #endif // C++17
1791 
1792 #endif // _GLIBCXX_VARIANT
constexpr _Tp && forward(typename std::remove_reference< _Tp >::type &__t) noexcept
Forward an lvalue.
Definition: move.h:76
void void_t
A metafunction that always yields void, used for detecting valid types.
Definition: type_traits:2576
constexpr _Tp * addressof(_Tp &__r) noexcept
Returns the actual address of the object or function referenced by r, even in the presence of an over...
Definition: move.h:140
typename add_pointer< _Tp >::type add_pointer_t
Alias template for add_pointer.
Definition: type_traits:2044
integral_constant
Definition: type_traits:57
make_integer_sequence< size_t, _Num > make_index_sequence
Alias template make_index_sequence.
Definition: utility:349
typename make_signed< _Tp >::type make_signed_t
Alias template for make_signed.
Definition: type_traits:1961
typename remove_reference< _Tp >::type remove_reference_t
Alias template for remove_reference.
Definition: type_traits:1635
integer_sequence< size_t, _Idx...> index_sequence
Alias template index_sequence.
Definition: utility:345
Class template integer_sequence.
Definition: utility:326
typename enable_if< _Cond, _Tp >::type enable_if_t
Alias template for enable_if.
Definition: type_traits:2554
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
Definition: move.h:101
integral_constant< bool, true > true_type
The type used as a compile-time boolean with true value.
Definition: type_traits:75
Primary class template hash.
Definition: typeindex:110
constexpr bool is_swappable_v
is_swappable_v
Definition: type_traits:2739
integral_constant< bool, false > false_type
The type used as a compile-time boolean with false value.
Definition: type_traits:78