[variant.visit] # 22 General utilities library [[utilities]](./#utilities) ## 22.6 Variants [[variant]](variant#visit) ### 22.6.7 Visitation [variant.visit] [🔗](#lib:visit) `template constexpr see below visit(Visitor&& vis, Variants&&... vars); template constexpr R visit(Visitor&& vis, Variants&&... vars); ` [1](#1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L6802) Let *as-variant* denote the following exposition-only function templates:templateconstexpr auto&& *as-variant*(variant& var) { return var; }templateconstexpr auto&& *as-variant*(const variant& var) { return var; }templateconstexpr auto&& *as-variant*(variant&& var) { return std::move(var); }templateconstexpr auto&& *as-variant*(const variant&& var) { return std::move(var); } Let n be sizeof...(Variants)[.](#1.sentence-2) For each 0≤i(varsi)))[.](#1.sentence-3) [2](#2) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L6819) *Constraints*: Vi is a valid type for all 0≤i> for all 0≤i(vis), *GET*(std::forward(vars))...) // see [[func.require]](func.require "22.10.4 Requirements") for the first form and*INVOKE*(std::forward(vis), *GET*(std::forward(vars))...) // see [[func.require]](func.require "22.10.4 Requirements") for the second form[.](#4.sentence-3) [5](#5) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L6841) *Mandates*: For each valid pack m, e(m) is a valid expression[.](#5.sentence-1) All such expressions are of the same type and value category[.](#5.sentence-2) [6](#6) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L6846) *Returns*: e(m), where m is the pack for whichmi is *as-variant*(varsi).index() for all 0≤i1, the invocation of the callable object has no complexity requirements[.](#8.sentence-2) [🔗](#lib:visit,variant_) `template constexpr decltype(auto) visit(this Self&& self, Visitor&& vis); ` [9](#9) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L6875) Let V be*OVERRIDE_REF*(Self&&, *COPY_CONST*(remove_reference_t, variant)) ([[forward]](forward "22.2.4 Forward/move helpers"))[.](#9.sentence-1) [10](#10) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L6879) *Constraints*: The call to visit does not use an explicit [*template-argument-list*](temp.names#nt:template-argument-list "13.3 Names of template specializations [temp.names]") that begins with a type [*template-argument*](temp.names#nt:template-argument "13.3 Names of template specializations [temp.names]")[.](#10.sentence-1) [11](#11) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L6885) *Effects*: Equivalent to: return std​::​visit(std​::​forward(vis), (V)self); [🔗](#lib:visit,variant__) `template constexpr R visit(this Self&& self, Visitor&& vis); ` [12](#12) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L6897) Let V be*OVERRIDE_REF*(Self&&, *COPY_CONST*(remove_reference_t, variant)) ([[forward]](forward "22.2.4 Forward/move helpers"))[.](#12.sentence-1) [13](#13) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L6901) *Effects*: Equivalent to: return std​::​visit(std​::​forward(vis), (V)self);