22 General utilities library [utilities]

22.6 Variants [variant]

22.6.7 Visitation [variant.visit]

template<class Visitor, class. Variants> constexpr see below visit(Visitor&& vis, Variants&&. vars); template<class R, class Visitor, class. Variants> constexpr R visit(Visitor&& vis, Variants&&. vars);
Let as-variant denote the following exposition-only function templates: template<class. Ts> constexpr auto& as-variant(variant<Ts..>& var) { return var; } template<class. Ts> constexpr auto& as-variant(const variant<Ts..>& var) { return var; } template<class. Ts> constexpr auto& as-variant(variant<Ts..>& var) { return std::move(var); } template<class. Ts> constexpr auto& as-variant(const variant<Ts..>& var) { return std::move(var); }
Let n be sizeof.(Variants).
For each
Let m be a pack of n values of type size_t.
Such a pack is valid if
For each valid pack m, let e(m) denote the expression: INVOKE(std::forward<Visitor>(vis), GET<m>(std::forward<V>(vars)).) / see [func.require] for the first form and INVOKE<R>(std::forward<Visitor>(vis), GET<m>(std::forward<V>(vars)).) / see [func.require] for the second form.
Returns: e(m), where m is the pack for which
The return type is decltype(e(m)) for the first form.
Throws: bad_variant_access if (as-variant(vars).valueless_by_exception() || ..) is true.
Complexity: For n  ≤ 1, the invocation of the callable object is implemented in constant time, i.e., for
For
template<class Self, class Visitor> constexpr decltype(auto) visit(this Self&& self, Visitor&& vis);
Let V be OVERRIDE_REF(Self&&, COPY_CONST(remove_reference_t<Self>, variant)) ([forward]).
Constraints: The call to visit does not use an explicit template-argument-list that begins with a type template-argument.
Effects: Equivalent to: return std​::​visit(std​::​forward<Visitor>(vis), (V)self);
template<class R, class Self, class Visitor> constexpr R visit(this Self&& self, Visitor&& vis);
Let V be OVERRIDE_REF(Self&&, COPY_CONST(remove_reference_t<Self>, variant)) ([forward]).
Effects: Equivalent to: return std​::​visit<R>(std​::​forward<Visitor>(vis), (V)self);

Follow Lee on X/Twitter - Father, Husband, Serial builder creating AI, crypto, games & web tools. We are friends :) AI Will Come To Life!

Check out: eBank.nz (Art Generator) | Netwrck.com (AI Tools) | Text-Generator.io (AI API) | BitBank.nz (Crypto AI) | ReadingTime (Kids Reading) | RewordGame | BigMultiplayerChess | WebFiddle | How.nz | Helix AI Assistant