@@ -69,6 +69,12 @@ namespace std {
69
69
70
70
// 20.7.2.6, swap
71
71
void swap(variant&) noexcept(see below);
72
+
73
+ // [variant.visit], visitation
74
+ template<class Self, class Visitor>
75
+ constexpr decltype(auto) visit(this Self&&, Visitor&&); // Since C++26
76
+ template<class R, class Self, class Visitor>
77
+ constexpr R visit(this Self&&, Visitor&&); // Since C++26
72
78
};
73
79
74
80
// 20.7.3, variant helper classes
@@ -235,6 +241,7 @@ namespace std {
235
241
#include < __type_traits/void_t.h>
236
242
#include < __utility/declval.h>
237
243
#include < __utility/forward.h>
244
+ #include < __utility/forward_like.h>
238
245
#include < __utility/in_place.h>
239
246
#include < __utility/move.h>
240
247
#include < __utility/swap.h>
@@ -1130,6 +1137,19 @@ using __best_match_t = typename invoke_result_t<_MakeOverloads<_Types...>, _Tp,
1130
1137
1131
1138
} // namespace __variant_detail
1132
1139
1140
+ template <class _Visitor , class ... _Vs, typename = void_t <decltype(std::__as_variant(std::declval<_Vs>()))...>>
1141
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS constexpr decltype (auto )
1142
+ visit(_Visitor&& __visitor, _Vs&&... __vs);
1143
+
1144
+ # if _LIBCPP_STD_VER >= 20
1145
+ template <class _Rp ,
1146
+ class _Visitor ,
1147
+ class ... _Vs,
1148
+ typename = void_t <decltype(std::__as_variant(std::declval<_Vs>()))...>>
1149
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS constexpr _Rp
1150
+ visit (_Visitor&& __visitor, _Vs&&... __vs);
1151
+ # endif
1152
+
1133
1153
template <class ... _Types>
1134
1154
class _LIBCPP_TEMPLATE_VIS _LIBCPP_DECLSPEC_EMPTY_BASES variant
1135
1155
: private __sfinae_ctor_base< __all<is_copy_constructible_v<_Types>...>::value,
@@ -1273,6 +1293,27 @@ public:
1273
1293
__impl_.__swap (__that.__impl_ );
1274
1294
}
1275
1295
1296
+ # if _LIBCPP_STD_VER >= 26 && defined(_LIBCPP_HAS_EXPLICIT_THIS_PARAMETER)
1297
+ // Helper class to implement [variant.visit]/10
1298
+ // Constraints: The call to visit does not use an explicit template-argument-list
1299
+ // that begins with a type template-argument.
1300
+ struct __variant_visit_barrier_tag {
1301
+ _LIBCPP_HIDE_FROM_ABI explicit __variant_visit_barrier_tag () = default;
1302
+ };
1303
+
1304
+ template <__variant_visit_barrier_tag = __variant_visit_barrier_tag{}, class _Self , class _Visitor >
1305
+ _LIBCPP_HIDE_FROM_ABI constexpr decltype (auto ) visit(this _Self&& __self, _Visitor&& __visitor) {
1306
+ using _VariantT = _OverrideRef<_Self&&, _CopyConst<remove_reference_t <_Self>, variant>>;
1307
+ return std::visit (std::forward<_Visitor>(__visitor), (_VariantT)__self);
1308
+ }
1309
+
1310
+ template <class _Rp , class _Self , class _Visitor >
1311
+ _LIBCPP_HIDE_FROM_ABI constexpr _Rp visit (this _Self&& __self, _Visitor&& __visitor) {
1312
+ using _VariantT = _OverrideRef<_Self&&, _CopyConst<remove_reference_t <_Self>, variant>>;
1313
+ return std::visit<_Rp>(std::forward<_Visitor>(__visitor), (_VariantT)__self);
1314
+ }
1315
+ # endif
1316
+
1276
1317
private:
1277
1318
__variant_detail::__impl<_Types...> __impl_;
1278
1319
@@ -1511,7 +1552,7 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS constexpr vo
1511
1552
}
1512
1553
}
1513
1554
1514
- template < class _Visitor , class ... _Vs, typename = void_t <decltype(std::__as_variant(std::declval<_Vs>()))...> >
1555
+ template < class _Visitor , class ... _Vs, typename >
1515
1556
_LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS constexpr decltype (auto )
1516
1557
visit(_Visitor&& __visitor, _Vs&&... __vs) {
1517
1558
using __variant_detail::__visitation::__variant;
@@ -1520,10 +1561,7 @@ visit(_Visitor&& __visitor, _Vs&&... __vs) {
1520
1561
}
1521
1562
1522
1563
# if _LIBCPP_STD_VER >= 20
1523
- template < class _Rp ,
1524
- class _Visitor ,
1525
- class ... _Vs,
1526
- typename = void_t <decltype(std::__as_variant(std::declval<_Vs>()))...> >
1564
+ template < class _Rp , class _Visitor , class ... _Vs, typename >
1527
1565
_LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS constexpr _Rp
1528
1566
visit (_Visitor&& __visitor, _Vs&&... __vs) {
1529
1567
using __variant_detail::__visitation::__variant;
0 commit comments